Manipulating a general length functionGeneral function taking general number of argumentsManipulating ListHow...

Luggage storage for 10 day in Tokyo

Knowing when to use pictures over words

Tikzing a circled star

Can a person refuse a presidential pardon?

Eww, those bytes are gross

How can animals be objects of ethics without being subjects as well?

How would one buy a used TIE Fighter or X-Wing?

How can I deal with a significant flaw I found in my previous supervisor’s paper?

How to deal with an incendiary email that was recalled

What makes the Forgotten Realms "forgotten"?

Are there any outlying considerations if I treat donning a shield as an object interaction during the first round of combat?

What is this metal M-shaped device for?

Does my logo design convey the right feelings for a University Student's Council?

How Internet Communication Works on a Coaxial Cable

If I delete my router's history can my ISP still provide it to my parents?

Could flying insects re-enter the Earth's atmosphere from space without burning up?

Find minimum number of meeting periods to reach 2 degrees of separation for a group

What kind of hardware implements Fourier transform?

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

How to remove trailing forward slash

How do creatures spend Hit Dice after a short rest (if they can do so)?

Program that converts a number to a letter of the alphabet

Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?

It took me a lot of time to make this, pls like. (YouTube Comments #1)



Manipulating a general length function


General function taking general number of argumentsManipulating ListHow to delete mirror symmetric point pair efficientlyConvert Integer to Numeric with Replacement rulesManipulating arrayManipulating List?Coefficient of function with general argumentFinding negative sequences in a large list: optimizationDefining general odd functionLinear operator algebra: How to distinguish scalars and operators?Manipulating lists













3












$begingroup$


As a minimal example, define a function like s[1,2,3]; this is a function of three arguments in this case, but I'd like to apply this general idea to functions like s[3,4,5,6,7] which don't necessarily start at 1.



From an identity from theory, I need to re-express this as as sum of 2-argument functions that cycle over all of the possible combinations of the original function, but don't duplicate. Explicitly, this would be the same as writing



s[1,2,3]=f[1,2]+f[1,3]+f[2,3],



or in the longer more general case (and to illustrate my point)



s[3,4,5,6,7] = f[3,4]+f[3,5]+f[3,6]+f[3,7]+f[4,5]+f[4,6]+f[4,7]+f[5,6]+f[5,7]+f[6,7]


I was previously using the definition with simple replacement rules for each of the these chains, with general cases of s[i_,j_,k_] and such similar rules. However, this isn't optimal in larger problems, where I have many thousands of these results, and leads to remarkably long evaluation times.



To see my functional but slow solution, I have attached a partial screenshot here, but naturally, I think there must be a better method. I was considering using Partitions, as in this SE post or BlankSpaces, but I struggle to implement more complex uses of these. Any guidance or other ideas would be gratefully appreciated. Also, a title suggestion would be great as well!










share|improve this question









$endgroup$












  • $begingroup$
    Look into Subsets[listOfArguments, {2}]
    $endgroup$
    – MarcoB
    1 hour ago
















3












$begingroup$


As a minimal example, define a function like s[1,2,3]; this is a function of three arguments in this case, but I'd like to apply this general idea to functions like s[3,4,5,6,7] which don't necessarily start at 1.



From an identity from theory, I need to re-express this as as sum of 2-argument functions that cycle over all of the possible combinations of the original function, but don't duplicate. Explicitly, this would be the same as writing



s[1,2,3]=f[1,2]+f[1,3]+f[2,3],



or in the longer more general case (and to illustrate my point)



s[3,4,5,6,7] = f[3,4]+f[3,5]+f[3,6]+f[3,7]+f[4,5]+f[4,6]+f[4,7]+f[5,6]+f[5,7]+f[6,7]


I was previously using the definition with simple replacement rules for each of the these chains, with general cases of s[i_,j_,k_] and such similar rules. However, this isn't optimal in larger problems, where I have many thousands of these results, and leads to remarkably long evaluation times.



To see my functional but slow solution, I have attached a partial screenshot here, but naturally, I think there must be a better method. I was considering using Partitions, as in this SE post or BlankSpaces, but I struggle to implement more complex uses of these. Any guidance or other ideas would be gratefully appreciated. Also, a title suggestion would be great as well!










share|improve this question









$endgroup$












  • $begingroup$
    Look into Subsets[listOfArguments, {2}]
    $endgroup$
    – MarcoB
    1 hour ago














3












3








3





$begingroup$


As a minimal example, define a function like s[1,2,3]; this is a function of three arguments in this case, but I'd like to apply this general idea to functions like s[3,4,5,6,7] which don't necessarily start at 1.



From an identity from theory, I need to re-express this as as sum of 2-argument functions that cycle over all of the possible combinations of the original function, but don't duplicate. Explicitly, this would be the same as writing



s[1,2,3]=f[1,2]+f[1,3]+f[2,3],



or in the longer more general case (and to illustrate my point)



s[3,4,5,6,7] = f[3,4]+f[3,5]+f[3,6]+f[3,7]+f[4,5]+f[4,6]+f[4,7]+f[5,6]+f[5,7]+f[6,7]


I was previously using the definition with simple replacement rules for each of the these chains, with general cases of s[i_,j_,k_] and such similar rules. However, this isn't optimal in larger problems, where I have many thousands of these results, and leads to remarkably long evaluation times.



To see my functional but slow solution, I have attached a partial screenshot here, but naturally, I think there must be a better method. I was considering using Partitions, as in this SE post or BlankSpaces, but I struggle to implement more complex uses of these. Any guidance or other ideas would be gratefully appreciated. Also, a title suggestion would be great as well!










share|improve this question









$endgroup$




As a minimal example, define a function like s[1,2,3]; this is a function of three arguments in this case, but I'd like to apply this general idea to functions like s[3,4,5,6,7] which don't necessarily start at 1.



From an identity from theory, I need to re-express this as as sum of 2-argument functions that cycle over all of the possible combinations of the original function, but don't duplicate. Explicitly, this would be the same as writing



s[1,2,3]=f[1,2]+f[1,3]+f[2,3],



or in the longer more general case (and to illustrate my point)



s[3,4,5,6,7] = f[3,4]+f[3,5]+f[3,6]+f[3,7]+f[4,5]+f[4,6]+f[4,7]+f[5,6]+f[5,7]+f[6,7]


I was previously using the definition with simple replacement rules for each of the these chains, with general cases of s[i_,j_,k_] and such similar rules. However, this isn't optimal in larger problems, where I have many thousands of these results, and leads to remarkably long evaluation times.



To see my functional but slow solution, I have attached a partial screenshot here, but naturally, I think there must be a better method. I was considering using Partitions, as in this SE post or BlankSpaces, but I struggle to implement more complex uses of these. Any guidance or other ideas would be gratefully appreciated. Also, a title suggestion would be great as well!







list-manipulation performance-tuning pattern-matching






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









BradBrad

647




647












  • $begingroup$
    Look into Subsets[listOfArguments, {2}]
    $endgroup$
    – MarcoB
    1 hour ago


















  • $begingroup$
    Look into Subsets[listOfArguments, {2}]
    $endgroup$
    – MarcoB
    1 hour ago
















$begingroup$
Look into Subsets[listOfArguments, {2}]
$endgroup$
– MarcoB
1 hour ago




$begingroup$
Look into Subsets[listOfArguments, {2}]
$endgroup$
– MarcoB
1 hour ago










2 Answers
2






active

oldest

votes


















4












$begingroup$

Something like the following?



ClearAll[s]
s[seq__] := Total[f@@@Subsets[List[seq], {2}]]





share|improve this answer









$endgroup$













  • $begingroup$
    Hi @MarcoB - Subsets was indeed the function I was looking for. I was thinking perhaps of more of a general replacement rule at the end, where in my final stage I remove all of the (previously defined) functions s, in exchange for these functions p. I will try and play around and see if I can figure out how to create a replacement rule based on this method. Thank you for your help:
    $endgroup$
    – Brad
    1 hour ago





















3












$begingroup$

ClearAll[s]
s[f_] := Total @ Subsets[f @ ##, {2}] &;

s[f][a, b, c]



f[a, b] + f[a, c] + f[b, c]




s[f][3, 4, 5, 6, 7]



f[3, 4] + f[3, 5] + f[3, 6] + f[3, 7] + f[4, 5] + f[4, 6] + f[4, 7] +
f[5, 6] + f[5, 7] + f[6, 7]







share|improve this answer











$endgroup$













    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%2f192481%2fmanipulating-a-general-length-function%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









    4












    $begingroup$

    Something like the following?



    ClearAll[s]
    s[seq__] := Total[f@@@Subsets[List[seq], {2}]]





    share|improve this answer









    $endgroup$













    • $begingroup$
      Hi @MarcoB - Subsets was indeed the function I was looking for. I was thinking perhaps of more of a general replacement rule at the end, where in my final stage I remove all of the (previously defined) functions s, in exchange for these functions p. I will try and play around and see if I can figure out how to create a replacement rule based on this method. Thank you for your help:
      $endgroup$
      – Brad
      1 hour ago


















    4












    $begingroup$

    Something like the following?



    ClearAll[s]
    s[seq__] := Total[f@@@Subsets[List[seq], {2}]]





    share|improve this answer









    $endgroup$













    • $begingroup$
      Hi @MarcoB - Subsets was indeed the function I was looking for. I was thinking perhaps of more of a general replacement rule at the end, where in my final stage I remove all of the (previously defined) functions s, in exchange for these functions p. I will try and play around and see if I can figure out how to create a replacement rule based on this method. Thank you for your help:
      $endgroup$
      – Brad
      1 hour ago
















    4












    4








    4





    $begingroup$

    Something like the following?



    ClearAll[s]
    s[seq__] := Total[f@@@Subsets[List[seq], {2}]]





    share|improve this answer









    $endgroup$



    Something like the following?



    ClearAll[s]
    s[seq__] := Total[f@@@Subsets[List[seq], {2}]]






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 1 hour ago









    MarcoBMarcoB

    36.5k556112




    36.5k556112












    • $begingroup$
      Hi @MarcoB - Subsets was indeed the function I was looking for. I was thinking perhaps of more of a general replacement rule at the end, where in my final stage I remove all of the (previously defined) functions s, in exchange for these functions p. I will try and play around and see if I can figure out how to create a replacement rule based on this method. Thank you for your help:
      $endgroup$
      – Brad
      1 hour ago




















    • $begingroup$
      Hi @MarcoB - Subsets was indeed the function I was looking for. I was thinking perhaps of more of a general replacement rule at the end, where in my final stage I remove all of the (previously defined) functions s, in exchange for these functions p. I will try and play around and see if I can figure out how to create a replacement rule based on this method. Thank you for your help:
      $endgroup$
      – Brad
      1 hour ago


















    $begingroup$
    Hi @MarcoB - Subsets was indeed the function I was looking for. I was thinking perhaps of more of a general replacement rule at the end, where in my final stage I remove all of the (previously defined) functions s, in exchange for these functions p. I will try and play around and see if I can figure out how to create a replacement rule based on this method. Thank you for your help:
    $endgroup$
    – Brad
    1 hour ago






    $begingroup$
    Hi @MarcoB - Subsets was indeed the function I was looking for. I was thinking perhaps of more of a general replacement rule at the end, where in my final stage I remove all of the (previously defined) functions s, in exchange for these functions p. I will try and play around and see if I can figure out how to create a replacement rule based on this method. Thank you for your help:
    $endgroup$
    – Brad
    1 hour ago













    3












    $begingroup$

    ClearAll[s]
    s[f_] := Total @ Subsets[f @ ##, {2}] &;

    s[f][a, b, c]



    f[a, b] + f[a, c] + f[b, c]




    s[f][3, 4, 5, 6, 7]



    f[3, 4] + f[3, 5] + f[3, 6] + f[3, 7] + f[4, 5] + f[4, 6] + f[4, 7] +
    f[5, 6] + f[5, 7] + f[6, 7]







    share|improve this answer











    $endgroup$


















      3












      $begingroup$

      ClearAll[s]
      s[f_] := Total @ Subsets[f @ ##, {2}] &;

      s[f][a, b, c]



      f[a, b] + f[a, c] + f[b, c]




      s[f][3, 4, 5, 6, 7]



      f[3, 4] + f[3, 5] + f[3, 6] + f[3, 7] + f[4, 5] + f[4, 6] + f[4, 7] +
      f[5, 6] + f[5, 7] + f[6, 7]







      share|improve this answer











      $endgroup$
















        3












        3








        3





        $begingroup$

        ClearAll[s]
        s[f_] := Total @ Subsets[f @ ##, {2}] &;

        s[f][a, b, c]



        f[a, b] + f[a, c] + f[b, c]




        s[f][3, 4, 5, 6, 7]



        f[3, 4] + f[3, 5] + f[3, 6] + f[3, 7] + f[4, 5] + f[4, 6] + f[4, 7] +
        f[5, 6] + f[5, 7] + f[6, 7]







        share|improve this answer











        $endgroup$



        ClearAll[s]
        s[f_] := Total @ Subsets[f @ ##, {2}] &;

        s[f][a, b, c]



        f[a, b] + f[a, c] + f[b, c]




        s[f][3, 4, 5, 6, 7]



        f[3, 4] + f[3, 5] + f[3, 6] + f[3, 7] + f[4, 5] + f[4, 6] + f[4, 7] +
        f[5, 6] + f[5, 7] + f[6, 7]








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 35 mins ago

























        answered 49 mins ago









        kglrkglr

        186k10203422




        186k10203422






























            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%2f192481%2fmanipulating-a-general-length-function%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

            Fairchild Swearingen Metro Inhaltsverzeichnis Geschichte | Innenausstattung | Nutzung | Zwischenfälle...

            Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...

            Marineschifffahrtleitung Inhaltsverzeichnis Geschichte | Heutige Organisation der NATO | Nationale und...