How to “split” a function with two separate arguments of the form F[X][Y]?
$begingroup$
I recently stumbled upon a function F[X][Y] that has two separate arguments X,Y. Note that it is not of the form F[X, Y]!
So for F[X][Y], first F acts on X and then F[X] acts on Y. Now for the purposes of my work I need to split the function F = F1 + F2, but I can't successfully feed the second argument Y neither F1[X] nor F2[X] in the end.
Here's my description in code:
F[X][Y]
% /. F -> (F1[#] + F2[#] &)
this gives as an output
(F1[X] + F2[X])[Y]
but what I need as a desired output is
F1[X][Y] + F2[X][Y]
So my question is:
How can one start from F[X][Y] so that one ends up with the desired output F1[X][Y] + F2[X][Y]?
Bonus question.
Can the above happen by only changing the head of F?, i.e., modifying the rule /. F -> (F1[#] + F2[#] &) somehow?
function-construction
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I recently stumbled upon a function F[X][Y] that has two separate arguments X,Y. Note that it is not of the form F[X, Y]!
So for F[X][Y], first F acts on X and then F[X] acts on Y. Now for the purposes of my work I need to split the function F = F1 + F2, but I can't successfully feed the second argument Y neither F1[X] nor F2[X] in the end.
Here's my description in code:
F[X][Y]
% /. F -> (F1[#] + F2[#] &)
this gives as an output
(F1[X] + F2[X])[Y]
but what I need as a desired output is
F1[X][Y] + F2[X][Y]
So my question is:
How can one start from F[X][Y] so that one ends up with the desired output F1[X][Y] + F2[X][Y]?
Bonus question.
Can the above happen by only changing the head of F?, i.e., modifying the rule /. F -> (F1[#] + F2[#] &) somehow?
function-construction
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
7
$begingroup$
% /. F -> (F1[#] + F2[#] &) // Through
$endgroup$
– Coolwater
10 hours ago
4
$begingroup$
% /. F[x_][y_] -> F1[x][y] + F2[x][y]
$endgroup$
– Roman
10 hours ago
$begingroup$
Thank you both a lot for your fast answers, both of them work perfectly.
$endgroup$
– Viktor Gakis
9 hours ago
add a comment |
$begingroup$
I recently stumbled upon a function F[X][Y] that has two separate arguments X,Y. Note that it is not of the form F[X, Y]!
So for F[X][Y], first F acts on X and then F[X] acts on Y. Now for the purposes of my work I need to split the function F = F1 + F2, but I can't successfully feed the second argument Y neither F1[X] nor F2[X] in the end.
Here's my description in code:
F[X][Y]
% /. F -> (F1[#] + F2[#] &)
this gives as an output
(F1[X] + F2[X])[Y]
but what I need as a desired output is
F1[X][Y] + F2[X][Y]
So my question is:
How can one start from F[X][Y] so that one ends up with the desired output F1[X][Y] + F2[X][Y]?
Bonus question.
Can the above happen by only changing the head of F?, i.e., modifying the rule /. F -> (F1[#] + F2[#] &) somehow?
function-construction
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I recently stumbled upon a function F[X][Y] that has two separate arguments X,Y. Note that it is not of the form F[X, Y]!
So for F[X][Y], first F acts on X and then F[X] acts on Y. Now for the purposes of my work I need to split the function F = F1 + F2, but I can't successfully feed the second argument Y neither F1[X] nor F2[X] in the end.
Here's my description in code:
F[X][Y]
% /. F -> (F1[#] + F2[#] &)
this gives as an output
(F1[X] + F2[X])[Y]
but what I need as a desired output is
F1[X][Y] + F2[X][Y]
So my question is:
How can one start from F[X][Y] so that one ends up with the desired output F1[X][Y] + F2[X][Y]?
Bonus question.
Can the above happen by only changing the head of F?, i.e., modifying the rule /. F -> (F1[#] + F2[#] &) somehow?
function-construction
function-construction
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 8 hours ago
m_goldberg
85.9k872196
85.9k872196
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 10 hours ago
Viktor GakisViktor Gakis
212
212
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Viktor Gakis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7
$begingroup$
% /. F -> (F1[#] + F2[#] &) // Through
$endgroup$
– Coolwater
10 hours ago
4
$begingroup$
% /. F[x_][y_] -> F1[x][y] + F2[x][y]
$endgroup$
– Roman
10 hours ago
$begingroup$
Thank you both a lot for your fast answers, both of them work perfectly.
$endgroup$
– Viktor Gakis
9 hours ago
add a comment |
7
$begingroup$
% /. F -> (F1[#] + F2[#] &) // Through
$endgroup$
– Coolwater
10 hours ago
4
$begingroup$
% /. F[x_][y_] -> F1[x][y] + F2[x][y]
$endgroup$
– Roman
10 hours ago
$begingroup$
Thank you both a lot for your fast answers, both of them work perfectly.
$endgroup$
– Viktor Gakis
9 hours ago
7
7
$begingroup$
% /. F -> (F1[#] + F2[#] &) // Through$endgroup$
– Coolwater
10 hours ago
$begingroup$
% /. F -> (F1[#] + F2[#] &) // Through$endgroup$
– Coolwater
10 hours ago
4
4
$begingroup$
% /. F[x_][y_] -> F1[x][y] + F2[x][y]$endgroup$
– Roman
10 hours ago
$begingroup$
% /. F[x_][y_] -> F1[x][y] + F2[x][y]$endgroup$
– Roman
10 hours ago
$begingroup$
Thank you both a lot for your fast answers, both of them work perfectly.
$endgroup$
– Viktor Gakis
9 hours ago
$begingroup$
Thank you both a lot for your fast answers, both of them work perfectly.
$endgroup$
– Viktor Gakis
9 hours ago
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
To address the 'Bonus question':
F[subFs_List, args__] := Total[Through[subFs[args]]] /. h_[x_, y__] /; MemberQ[subFs, h] :> h[x][y]
Evaluating F[{F1,F2},X,Y] returns
F1[X][Y]+F2[X][Y]
as expected
$endgroup$
add a comment |
$begingroup$
Just write it like any other function definition.
f[x_][y_] := f1[x][y] + f2[x][y]
Then
f[u][v]
gives
f1[u][v] + f2[u][v]
$endgroup$
add a comment |
$begingroup$
Through @ Operate[Apply[Plus @@ Through[{f1, f2} @ #] &], f[x][y]]
f1[x][y] + f2[x][y]
$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
});
}
});
Viktor Gakis 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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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%2f191189%2fhow-to-split-a-function-with-two-separate-arguments-of-the-form-fxy%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$
To address the 'Bonus question':
F[subFs_List, args__] := Total[Through[subFs[args]]] /. h_[x_, y__] /; MemberQ[subFs, h] :> h[x][y]
Evaluating F[{F1,F2},X,Y] returns
F1[X][Y]+F2[X][Y]
as expected
$endgroup$
add a comment |
$begingroup$
To address the 'Bonus question':
F[subFs_List, args__] := Total[Through[subFs[args]]] /. h_[x_, y__] /; MemberQ[subFs, h] :> h[x][y]
Evaluating F[{F1,F2},X,Y] returns
F1[X][Y]+F2[X][Y]
as expected
$endgroup$
add a comment |
$begingroup$
To address the 'Bonus question':
F[subFs_List, args__] := Total[Through[subFs[args]]] /. h_[x_, y__] /; MemberQ[subFs, h] :> h[x][y]
Evaluating F[{F1,F2},X,Y] returns
F1[X][Y]+F2[X][Y]
as expected
$endgroup$
To address the 'Bonus question':
F[subFs_List, args__] := Total[Through[subFs[args]]] /. h_[x_, y__] /; MemberQ[subFs, h] :> h[x][y]
Evaluating F[{F1,F2},X,Y] returns
F1[X][Y]+F2[X][Y]
as expected
answered 9 hours ago
user42582user42582
2,8431524
2,8431524
add a comment |
add a comment |
$begingroup$
Just write it like any other function definition.
f[x_][y_] := f1[x][y] + f2[x][y]
Then
f[u][v]
gives
f1[u][v] + f2[u][v]
$endgroup$
add a comment |
$begingroup$
Just write it like any other function definition.
f[x_][y_] := f1[x][y] + f2[x][y]
Then
f[u][v]
gives
f1[u][v] + f2[u][v]
$endgroup$
add a comment |
$begingroup$
Just write it like any other function definition.
f[x_][y_] := f1[x][y] + f2[x][y]
Then
f[u][v]
gives
f1[u][v] + f2[u][v]
$endgroup$
Just write it like any other function definition.
f[x_][y_] := f1[x][y] + f2[x][y]
Then
f[u][v]
gives
f1[u][v] + f2[u][v]
answered 8 hours ago
m_goldbergm_goldberg
85.9k872196
85.9k872196
add a comment |
add a comment |
$begingroup$
Through @ Operate[Apply[Plus @@ Through[{f1, f2} @ #] &], f[x][y]]
f1[x][y] + f2[x][y]
$endgroup$
add a comment |
$begingroup$
Through @ Operate[Apply[Plus @@ Through[{f1, f2} @ #] &], f[x][y]]
f1[x][y] + f2[x][y]
$endgroup$
add a comment |
$begingroup$
Through @ Operate[Apply[Plus @@ Through[{f1, f2} @ #] &], f[x][y]]
f1[x][y] + f2[x][y]
$endgroup$
Through @ Operate[Apply[Plus @@ Through[{f1, f2} @ #] &], f[x][y]]
f1[x][y] + f2[x][y]
answered 3 hours ago
kglrkglr
183k10200415
183k10200415
add a comment |
add a comment |
Viktor Gakis is a new contributor. Be nice, and check out our Code of Conduct.
Viktor Gakis is a new contributor. Be nice, and check out our Code of Conduct.
Viktor Gakis is a new contributor. Be nice, and check out our Code of Conduct.
Viktor Gakis 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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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%2f191189%2fhow-to-split-a-function-with-two-separate-arguments-of-the-form-fxy%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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
7
$begingroup$
% /. F -> (F1[#] + F2[#] &) // Through$endgroup$
– Coolwater
10 hours ago
4
$begingroup$
% /. F[x_][y_] -> F1[x][y] + F2[x][y]$endgroup$
– Roman
10 hours ago
$begingroup$
Thank you both a lot for your fast answers, both of them work perfectly.
$endgroup$
– Viktor Gakis
9 hours ago