Is there a simple way to apply a function to the RHS of a substitution?Assign the Background rule in Grid (the positions can be described by a integer function)ReplaceAll performance problem: packed arrays on the LHS are unpacked when the RHS is too longHow to select the value of a substitution rule for a particular variable?replace RHS of ruleWhy won't the Rule work? And how to apply it to a combination of variables?How does one unpack the contents of a list while using rules to substitute values for each variable?Why does syntax highlighting in `Set` and `Rule` not color pattern names on the RHS?What is the function of OrderedQ in these expressions?Make Mathematica apply the same rule exhaustively in simplification
DIY inkjet transparency film or photopaper
Is the net charge on a capacitor zero? If yes, then why?
Can the President be impeached twice?
Sorting marbles based on weightings
Does 'hacer alguien matar' mean to make somebody kill or to get sb killed?
How to pair a xrightarrow with text on the top) to a sort of xleftarrow (with text on the bottom)?
Undesired blank space between some words
Reference book or websites on how Mac OS works
Is a datagram from an upper network layer converted 1:1 to one of the lower layer?
Is it safe to wear earplugs in flight?
one list minus another
What's the greatest number of hands I can have to annoy my mother-in-law with?
Pass on your radiation
Secure Implementation of Password Database
Why is wired Ethernet losing its speed advantage over wireless?
How does a religion based around destroying the world attract followers
What are the disadvantages of using a Zener diode over a linear voltage regulator?
Who started calling the matrix multiplication "multiplication"?
How to deal with this fundamental problem with the advice: "Don't trust obscure PHP libraries that nobody uses!"?
Did a man complain that his Pontiac wouldn't start whenever the ice cream he picked up was vanilla?
Do photons have kinetic energy?
Will the same JavaScript fetched by HTTP and HTTPS be cached separately by the browser?
Acid-catalysed isomerisation of phenyl epoxide to aldehyde
Avoid long walking when changing between Tokyo subway lines
Is there a simple way to apply a function to the RHS of a substitution?
Assign the Background rule in Grid (the positions can be described by a integer function)ReplaceAll performance problem: packed arrays on the LHS are unpacked when the RHS is too longHow to select the value of a substitution rule for a particular variable?replace RHS of ruleWhy won't the Rule work? And how to apply it to a combination of variables?How does one unpack the contents of a list while using rules to substitute values for each variable?Why does syntax highlighting in `Set` and `Rule` not color pattern names on the RHS?What is the function of OrderedQ in these expressions?Make Mathematica apply the same rule exhaustively in simplification
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;
$begingroup$
Suppose I have solved a system of equations, resulting in a solution of the form:
sol = f[a1] -> SomeComplicatedFunction[x, a1], f[a2] -> SomeComplicatedFunction[x, a2], f[a3] -> SomeComplicatedFunction[x, a3]
I want to use the list of substitutions sol
later on, but first I want to apply some method myFunction
to the rhs of the substitution. I.e., the desired output is
sol = f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] -> myFunction[SomeComplicatedFunction[x, a2]], f[a3] -> myFunction[SomeComplicatedFunction[x, a3]]
I have tried extracting all the RHSs from sol
, applying myFunction
to the list, then setting this back to the original f[]
s, but this seems to be very inefficient. Is there some canonical Mathematica way of applying rules to solutions while keeping the solutions intact?
rule
$endgroup$
add a comment
|
$begingroup$
Suppose I have solved a system of equations, resulting in a solution of the form:
sol = f[a1] -> SomeComplicatedFunction[x, a1], f[a2] -> SomeComplicatedFunction[x, a2], f[a3] -> SomeComplicatedFunction[x, a3]
I want to use the list of substitutions sol
later on, but first I want to apply some method myFunction
to the rhs of the substitution. I.e., the desired output is
sol = f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] -> myFunction[SomeComplicatedFunction[x, a2]], f[a3] -> myFunction[SomeComplicatedFunction[x, a3]]
I have tried extracting all the RHSs from sol
, applying myFunction
to the list, then setting this back to the original f[]
s, but this seems to be very inefficient. Is there some canonical Mathematica way of applying rules to solutions while keeping the solutions intact?
rule
$endgroup$
add a comment
|
$begingroup$
Suppose I have solved a system of equations, resulting in a solution of the form:
sol = f[a1] -> SomeComplicatedFunction[x, a1], f[a2] -> SomeComplicatedFunction[x, a2], f[a3] -> SomeComplicatedFunction[x, a3]
I want to use the list of substitutions sol
later on, but first I want to apply some method myFunction
to the rhs of the substitution. I.e., the desired output is
sol = f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] -> myFunction[SomeComplicatedFunction[x, a2]], f[a3] -> myFunction[SomeComplicatedFunction[x, a3]]
I have tried extracting all the RHSs from sol
, applying myFunction
to the list, then setting this back to the original f[]
s, but this seems to be very inefficient. Is there some canonical Mathematica way of applying rules to solutions while keeping the solutions intact?
rule
$endgroup$
Suppose I have solved a system of equations, resulting in a solution of the form:
sol = f[a1] -> SomeComplicatedFunction[x, a1], f[a2] -> SomeComplicatedFunction[x, a2], f[a3] -> SomeComplicatedFunction[x, a3]
I want to use the list of substitutions sol
later on, but first I want to apply some method myFunction
to the rhs of the substitution. I.e., the desired output is
sol = f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] -> myFunction[SomeComplicatedFunction[x, a2]], f[a3] -> myFunction[SomeComplicatedFunction[x, a3]]
I have tried extracting all the RHSs from sol
, applying myFunction
to the list, then setting this back to the original f[]
s, but this seems to be very inefficient. Is there some canonical Mathematica way of applying rules to solutions while keeping the solutions intact?
rule
rule
asked Oct 1 at 0:13
user366202user366202
1475 bronze badges
1475 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
$begingroup$
sol =
f[a1] -> SomeComplicatedFunction[x, a1],
f[a2] -> SomeComplicatedFunction[x, a2],
f[a3] -> SomeComplicatedFunction[x, a3];
sol2 = sol /. Rule[lhs_, rhs_] :> Rule[lhs, myFunction[rhs]]
(* f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]], f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]] *)
$endgroup$
add a comment
|
$begingroup$
Additional alternatives:
You can use MapAt
to map myFunction
at positions All, -1, -1
:
sol3 = MapAt[myFunction, sol, All, -1, -1]
f[a1] -> myFunction[SomeComplicatedFunction[x, a1]],
f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]],
f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]]
You can assign new values at desired positions using Part
assignment:
sol4 = sol;
sol4[[All, -1, -1]] = myFunction /@ sol4[[All, -1, -1]];
sol4
same result
$endgroup$
add a comment
|
Your Answer
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/4.0/"u003ecc by-sa 4.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
);
);
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%2f207134%2fis-there-a-simple-way-to-apply-a-function-to-the-rhs-of-a-substitution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
sol =
f[a1] -> SomeComplicatedFunction[x, a1],
f[a2] -> SomeComplicatedFunction[x, a2],
f[a3] -> SomeComplicatedFunction[x, a3];
sol2 = sol /. Rule[lhs_, rhs_] :> Rule[lhs, myFunction[rhs]]
(* f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]], f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]] *)
$endgroup$
add a comment
|
$begingroup$
sol =
f[a1] -> SomeComplicatedFunction[x, a1],
f[a2] -> SomeComplicatedFunction[x, a2],
f[a3] -> SomeComplicatedFunction[x, a3];
sol2 = sol /. Rule[lhs_, rhs_] :> Rule[lhs, myFunction[rhs]]
(* f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]], f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]] *)
$endgroup$
add a comment
|
$begingroup$
sol =
f[a1] -> SomeComplicatedFunction[x, a1],
f[a2] -> SomeComplicatedFunction[x, a2],
f[a3] -> SomeComplicatedFunction[x, a3];
sol2 = sol /. Rule[lhs_, rhs_] :> Rule[lhs, myFunction[rhs]]
(* f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]], f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]] *)
$endgroup$
sol =
f[a1] -> SomeComplicatedFunction[x, a1],
f[a2] -> SomeComplicatedFunction[x, a2],
f[a3] -> SomeComplicatedFunction[x, a3];
sol2 = sol /. Rule[lhs_, rhs_] :> Rule[lhs, myFunction[rhs]]
(* f[a1] -> myFunction[SomeComplicatedFunction[x, a1]], f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]], f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]] *)
answered Oct 1 at 0:19
Bob HanlonBob Hanlon
70.4k3 gold badges40 silver badges110 bronze badges
70.4k3 gold badges40 silver badges110 bronze badges
add a comment
|
add a comment
|
$begingroup$
Additional alternatives:
You can use MapAt
to map myFunction
at positions All, -1, -1
:
sol3 = MapAt[myFunction, sol, All, -1, -1]
f[a1] -> myFunction[SomeComplicatedFunction[x, a1]],
f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]],
f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]]
You can assign new values at desired positions using Part
assignment:
sol4 = sol;
sol4[[All, -1, -1]] = myFunction /@ sol4[[All, -1, -1]];
sol4
same result
$endgroup$
add a comment
|
$begingroup$
Additional alternatives:
You can use MapAt
to map myFunction
at positions All, -1, -1
:
sol3 = MapAt[myFunction, sol, All, -1, -1]
f[a1] -> myFunction[SomeComplicatedFunction[x, a1]],
f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]],
f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]]
You can assign new values at desired positions using Part
assignment:
sol4 = sol;
sol4[[All, -1, -1]] = myFunction /@ sol4[[All, -1, -1]];
sol4
same result
$endgroup$
add a comment
|
$begingroup$
Additional alternatives:
You can use MapAt
to map myFunction
at positions All, -1, -1
:
sol3 = MapAt[myFunction, sol, All, -1, -1]
f[a1] -> myFunction[SomeComplicatedFunction[x, a1]],
f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]],
f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]]
You can assign new values at desired positions using Part
assignment:
sol4 = sol;
sol4[[All, -1, -1]] = myFunction /@ sol4[[All, -1, -1]];
sol4
same result
$endgroup$
Additional alternatives:
You can use MapAt
to map myFunction
at positions All, -1, -1
:
sol3 = MapAt[myFunction, sol, All, -1, -1]
f[a1] -> myFunction[SomeComplicatedFunction[x, a1]],
f[a2] ->
myFunction[SomeComplicatedFunction[x, a2]],
f[a3] ->
myFunction[SomeComplicatedFunction[x, a3]]
You can assign new values at desired positions using Part
assignment:
sol4 = sol;
sol4[[All, -1, -1]] = myFunction /@ sol4[[All, -1, -1]];
sol4
same result
answered Oct 1 at 1:04
kglrkglr
229k10 gold badges259 silver badges522 bronze badges
229k10 gold badges259 silver badges522 bronze badges
add a comment
|
add a comment
|
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%2f207134%2fis-there-a-simple-way-to-apply-a-function-to-the-rhs-of-a-substitution%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