Change arguments of a product of functions
$begingroup$
I am trying to do the following with rule-based pattern matching
(f1[t] f2[t] f3[t]) /. {x__ -> n[
Product[x[[i, 0]][om[i]], {i, 3}]]} // Quiet
which gives me the output n[f1[om[1]] f2[om[2]] f3[om[3]]]
. However, it seems as if one cannot specify parts of a pattern MMA gives the error messages
"Part specification x[[1,0]] is longer than depth of object"
I would like to do the operatoration for a product of n
arbitrary functions f1[t]
...fn[t]
where the number of functions is automatically detected (I cannot use Length
as well). How would one do it correctly?
pattern-matching
$endgroup$
add a comment |
$begingroup$
I am trying to do the following with rule-based pattern matching
(f1[t] f2[t] f3[t]) /. {x__ -> n[
Product[x[[i, 0]][om[i]], {i, 3}]]} // Quiet
which gives me the output n[f1[om[1]] f2[om[2]] f3[om[3]]]
. However, it seems as if one cannot specify parts of a pattern MMA gives the error messages
"Part specification x[[1,0]] is longer than depth of object"
I would like to do the operatoration for a product of n
arbitrary functions f1[t]
...fn[t]
where the number of functions is automatically detected (I cannot use Length
as well). How would one do it correctly?
pattern-matching
$endgroup$
add a comment |
$begingroup$
I am trying to do the following with rule-based pattern matching
(f1[t] f2[t] f3[t]) /. {x__ -> n[
Product[x[[i, 0]][om[i]], {i, 3}]]} // Quiet
which gives me the output n[f1[om[1]] f2[om[2]] f3[om[3]]]
. However, it seems as if one cannot specify parts of a pattern MMA gives the error messages
"Part specification x[[1,0]] is longer than depth of object"
I would like to do the operatoration for a product of n
arbitrary functions f1[t]
...fn[t]
where the number of functions is automatically detected (I cannot use Length
as well). How would one do it correctly?
pattern-matching
$endgroup$
I am trying to do the following with rule-based pattern matching
(f1[t] f2[t] f3[t]) /. {x__ -> n[
Product[x[[i, 0]][om[i]], {i, 3}]]} // Quiet
which gives me the output n[f1[om[1]] f2[om[2]] f3[om[3]]]
. However, it seems as if one cannot specify parts of a pattern MMA gives the error messages
"Part specification x[[1,0]] is longer than depth of object"
I would like to do the operatoration for a product of n
arbitrary functions f1[t]
...fn[t]
where the number of functions is automatically detected (I cannot use Length
as well). How would one do it correctly?
pattern-matching
pattern-matching
asked 3 hours ago
Display NameDisplay Name
56938
56938
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
f1[t] f2[t] f3[t] /. Times[x_, y__] :> n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Also
Module[{i = 1}, f1[t] f2[t] f3[t] /. {t :> om[i++]} // n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Update: "If all the functions are equal":
Inactivate[f1[t] f1[t] f1[t]] /.
Inactive[Times][x_, y__] :> Activate@n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
Activate@Module[{i = 1}, Inactivate[f1[t] f1[t] f1[t]] /. {t :> om[i++]} // n]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
$endgroup$
$begingroup$
Thank you for your answer. It works forf1 != f2 != f3
but stops working if all the functions are equal.
$endgroup$
– Display Name
58 mins ago
$begingroup$
@DisplayName, please see the update.
$endgroup$
– kglr
48 mins ago
$begingroup$
Thanks again. I think I lack a little bit of knowledge to come up with sth like this. I just read into pattern matching but it needs some time to settle. But I also like the approach with theRuleDelayed
. The mathematical background of this question is to write a product in time domain as a product in Fourier space via the convolution theorem.n
is then simply a functional involving integrations over theom
s.
$endgroup$
– Display Name
36 mins ago
add a comment |
$begingroup$
A simple function can do it.
changeArg[p : Times[__], var_Symbol, head_Symbol] :=
head[MapIndexed[#1[var[#2[[1]]]] &, Head /@ p]]
changeArg[f1[t] f2[t] f3[t], om, n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
$endgroup$
$begingroup$
Thank you for another possible answer. I think in the current form it doesn't cover the case of equal functions.
$endgroup$
– Display Name
22 mins ago
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
});
}
});
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%2f189658%2fchange-arguments-of-a-product-of-functions%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$
f1[t] f2[t] f3[t] /. Times[x_, y__] :> n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Also
Module[{i = 1}, f1[t] f2[t] f3[t] /. {t :> om[i++]} // n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Update: "If all the functions are equal":
Inactivate[f1[t] f1[t] f1[t]] /.
Inactive[Times][x_, y__] :> Activate@n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
Activate@Module[{i = 1}, Inactivate[f1[t] f1[t] f1[t]] /. {t :> om[i++]} // n]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
$endgroup$
$begingroup$
Thank you for your answer. It works forf1 != f2 != f3
but stops working if all the functions are equal.
$endgroup$
– Display Name
58 mins ago
$begingroup$
@DisplayName, please see the update.
$endgroup$
– kglr
48 mins ago
$begingroup$
Thanks again. I think I lack a little bit of knowledge to come up with sth like this. I just read into pattern matching but it needs some time to settle. But I also like the approach with theRuleDelayed
. The mathematical background of this question is to write a product in time domain as a product in Fourier space via the convolution theorem.n
is then simply a functional involving integrations over theom
s.
$endgroup$
– Display Name
36 mins ago
add a comment |
$begingroup$
f1[t] f2[t] f3[t] /. Times[x_, y__] :> n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Also
Module[{i = 1}, f1[t] f2[t] f3[t] /. {t :> om[i++]} // n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Update: "If all the functions are equal":
Inactivate[f1[t] f1[t] f1[t]] /.
Inactive[Times][x_, y__] :> Activate@n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
Activate@Module[{i = 1}, Inactivate[f1[t] f1[t] f1[t]] /. {t :> om[i++]} // n]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
$endgroup$
$begingroup$
Thank you for your answer. It works forf1 != f2 != f3
but stops working if all the functions are equal.
$endgroup$
– Display Name
58 mins ago
$begingroup$
@DisplayName, please see the update.
$endgroup$
– kglr
48 mins ago
$begingroup$
Thanks again. I think I lack a little bit of knowledge to come up with sth like this. I just read into pattern matching but it needs some time to settle. But I also like the approach with theRuleDelayed
. The mathematical background of this question is to write a product in time domain as a product in Fourier space via the convolution theorem.n
is then simply a functional involving integrations over theom
s.
$endgroup$
– Display Name
36 mins ago
add a comment |
$begingroup$
f1[t] f2[t] f3[t] /. Times[x_, y__] :> n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Also
Module[{i = 1}, f1[t] f2[t] f3[t] /. {t :> om[i++]} // n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Update: "If all the functions are equal":
Inactivate[f1[t] f1[t] f1[t]] /.
Inactive[Times][x_, y__] :> Activate@n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
Activate@Module[{i = 1}, Inactivate[f1[t] f1[t] f1[t]] /. {t :> om[i++]} // n]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
$endgroup$
f1[t] f2[t] f3[t] /. Times[x_, y__] :> n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Also
Module[{i = 1}, f1[t] f2[t] f3[t] /. {t :> om[i++]} // n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
Update: "If all the functions are equal":
Inactivate[f1[t] f1[t] f1[t]] /.
Inactive[Times][x_, y__] :> Activate@n[Times @@ MapIndexed[#[[0]][om[#2[[1]]]] &, {x, y}]]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
Activate@Module[{i = 1}, Inactivate[f1[t] f1[t] f1[t]] /. {t :> om[i++]} // n]
n[f1[om[1]] f1[om[2]] f1[om[3]]]
edited 49 mins ago
answered 1 hour ago
kglrkglr
179k9198410
179k9198410
$begingroup$
Thank you for your answer. It works forf1 != f2 != f3
but stops working if all the functions are equal.
$endgroup$
– Display Name
58 mins ago
$begingroup$
@DisplayName, please see the update.
$endgroup$
– kglr
48 mins ago
$begingroup$
Thanks again. I think I lack a little bit of knowledge to come up with sth like this. I just read into pattern matching but it needs some time to settle. But I also like the approach with theRuleDelayed
. The mathematical background of this question is to write a product in time domain as a product in Fourier space via the convolution theorem.n
is then simply a functional involving integrations over theom
s.
$endgroup$
– Display Name
36 mins ago
add a comment |
$begingroup$
Thank you for your answer. It works forf1 != f2 != f3
but stops working if all the functions are equal.
$endgroup$
– Display Name
58 mins ago
$begingroup$
@DisplayName, please see the update.
$endgroup$
– kglr
48 mins ago
$begingroup$
Thanks again. I think I lack a little bit of knowledge to come up with sth like this. I just read into pattern matching but it needs some time to settle. But I also like the approach with theRuleDelayed
. The mathematical background of this question is to write a product in time domain as a product in Fourier space via the convolution theorem.n
is then simply a functional involving integrations over theom
s.
$endgroup$
– Display Name
36 mins ago
$begingroup$
Thank you for your answer. It works for
f1 != f2 != f3
but stops working if all the functions are equal.$endgroup$
– Display Name
58 mins ago
$begingroup$
Thank you for your answer. It works for
f1 != f2 != f3
but stops working if all the functions are equal.$endgroup$
– Display Name
58 mins ago
$begingroup$
@DisplayName, please see the update.
$endgroup$
– kglr
48 mins ago
$begingroup$
@DisplayName, please see the update.
$endgroup$
– kglr
48 mins ago
$begingroup$
Thanks again. I think I lack a little bit of knowledge to come up with sth like this. I just read into pattern matching but it needs some time to settle. But I also like the approach with the
RuleDelayed
. The mathematical background of this question is to write a product in time domain as a product in Fourier space via the convolution theorem. n
is then simply a functional involving integrations over the om
s.$endgroup$
– Display Name
36 mins ago
$begingroup$
Thanks again. I think I lack a little bit of knowledge to come up with sth like this. I just read into pattern matching but it needs some time to settle. But I also like the approach with the
RuleDelayed
. The mathematical background of this question is to write a product in time domain as a product in Fourier space via the convolution theorem. n
is then simply a functional involving integrations over the om
s.$endgroup$
– Display Name
36 mins ago
add a comment |
$begingroup$
A simple function can do it.
changeArg[p : Times[__], var_Symbol, head_Symbol] :=
head[MapIndexed[#1[var[#2[[1]]]] &, Head /@ p]]
changeArg[f1[t] f2[t] f3[t], om, n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
$endgroup$
$begingroup$
Thank you for another possible answer. I think in the current form it doesn't cover the case of equal functions.
$endgroup$
– Display Name
22 mins ago
add a comment |
$begingroup$
A simple function can do it.
changeArg[p : Times[__], var_Symbol, head_Symbol] :=
head[MapIndexed[#1[var[#2[[1]]]] &, Head /@ p]]
changeArg[f1[t] f2[t] f3[t], om, n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
$endgroup$
$begingroup$
Thank you for another possible answer. I think in the current form it doesn't cover the case of equal functions.
$endgroup$
– Display Name
22 mins ago
add a comment |
$begingroup$
A simple function can do it.
changeArg[p : Times[__], var_Symbol, head_Symbol] :=
head[MapIndexed[#1[var[#2[[1]]]] &, Head /@ p]]
changeArg[f1[t] f2[t] f3[t], om, n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
$endgroup$
A simple function can do it.
changeArg[p : Times[__], var_Symbol, head_Symbol] :=
head[MapIndexed[#1[var[#2[[1]]]] &, Head /@ p]]
changeArg[f1[t] f2[t] f3[t], om, n]
n[f1[om[1]] f2[om[2]] f3[om[3]]]
answered 36 mins ago
m_goldbergm_goldberg
84.7k872196
84.7k872196
$begingroup$
Thank you for another possible answer. I think in the current form it doesn't cover the case of equal functions.
$endgroup$
– Display Name
22 mins ago
add a comment |
$begingroup$
Thank you for another possible answer. I think in the current form it doesn't cover the case of equal functions.
$endgroup$
– Display Name
22 mins ago
$begingroup$
Thank you for another possible answer. I think in the current form it doesn't cover the case of equal functions.
$endgroup$
– Display Name
22 mins ago
$begingroup$
Thank you for another possible answer. I think in the current form it doesn't cover the case of equal functions.
$endgroup$
– Display Name
22 mins ago
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');
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%2f189658%2fchange-arguments-of-a-product-of-functions%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