Change arguments of a product of functions












2












$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?










share|improve this question









$endgroup$

















    2












    $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?










    share|improve this question









    $endgroup$















      2












      2








      2





      $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?










      share|improve this question









      $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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 3 hours ago









      Display NameDisplay Name

      56938




      56938






















          2 Answers
          2






          active

          oldest

          votes


















          2












          $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]]]







          share|improve this answer











          $endgroup$













          • $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$
            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 oms.
            $endgroup$
            – Display Name
            36 mins ago





















          0












          $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]]]







          share|improve this answer









          $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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          2












          $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]]]







          share|improve this answer











          $endgroup$













          • $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$
            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 oms.
            $endgroup$
            – Display Name
            36 mins ago


















          2












          $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]]]







          share|improve this answer











          $endgroup$













          • $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$
            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 oms.
            $endgroup$
            – Display Name
            36 mins ago
















          2












          2








          2





          $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]]]







          share|improve this answer











          $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]]]








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 49 mins ago

























          answered 1 hour ago









          kglrkglr

          179k9198410




          179k9198410












          • $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$
            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 oms.
            $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$
            @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 oms.
            $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 oms.
          $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 oms.
          $endgroup$
          – Display Name
          36 mins ago













          0












          $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]]]







          share|improve this answer









          $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
















          0












          $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]]]







          share|improve this answer









          $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














          0












          0








          0





          $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]]]







          share|improve this answer









          $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]]]








          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • $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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Magento 2 controller redirect on button click in phtml file

          Polycentropodidae