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

A flower in a hexagon

What's a good word to describe a public place that looks like it wouldn't be rough?

How should I handle players who ignore the session zero agreement?

Why did Jodrell Bank assist the Soviet Union to collect data from their spacecraft in the mid 1960's?

I am on the US no-fly list. What can I do in order to be allowed on flights which go through US airspace?

Program that converts a number to a letter of the alphabet

Inferring from (∃x)Fx to (∃x)(∃x)Fx using existential generalization?

What is better: yes / no radio, or simple checkbox?

How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?

Rear brake cable temporary fix possible?

How to avoid being sexist when trying to employ someone to function in a very sexist environment?

How experienced do I need to be to go on a photography workshop?

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

When does coming up with an idea constitute sufficient contribution for authorship?

Does Windows 10's telemetry include sending *.doc files if Word crashed?

Using loops to create tables

Strange Sign on Lab Door

Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?

On what did Lego base the appearance of the new Hogwarts minifigs?

What's the most convenient time of year in the USA to end the world?

What is the wife of a henpecked husband called?

1 0 1 0 1 0 1 0 1 0 1

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

What is the best way to simulate grief?



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













5












$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
    15 hours ago
















5












$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
    15 hours ago














5












5








5





$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 16 hours ago









BradBrad

768




768












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


















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
















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




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










2 Answers
2






active

oldest

votes


















7












$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
    15 hours ago












  • $begingroup$
    After changing my definition of recursion to work with a symbolic sX, which actually makes evaluations much much faster overall, I can utilise this to get exactly what I need. Thank you all for your help, this is the fastest solution I found.
    $endgroup$
    – Brad
    13 hours ago



















7












$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









    7












    $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
      15 hours ago












    • $begingroup$
      After changing my definition of recursion to work with a symbolic sX, which actually makes evaluations much much faster overall, I can utilise this to get exactly what I need. Thank you all for your help, this is the fastest solution I found.
      $endgroup$
      – Brad
      13 hours ago
















    7












    $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
      15 hours ago












    • $begingroup$
      After changing my definition of recursion to work with a symbolic sX, which actually makes evaluations much much faster overall, I can utilise this to get exactly what I need. Thank you all for your help, this is the fastest solution I found.
      $endgroup$
      – Brad
      13 hours ago














    7












    7








    7





    $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 15 hours ago









    MarcoBMarcoB

    36.6k556112




    36.6k556112












    • $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
      15 hours ago












    • $begingroup$
      After changing my definition of recursion to work with a symbolic sX, which actually makes evaluations much much faster overall, I can utilise this to get exactly what I need. Thank you all for your help, this is the fastest solution I found.
      $endgroup$
      – Brad
      13 hours 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
      15 hours ago












    • $begingroup$
      After changing my definition of recursion to work with a symbolic sX, which actually makes evaluations much much faster overall, I can utilise this to get exactly what I need. Thank you all for your help, this is the fastest solution I found.
      $endgroup$
      – Brad
      13 hours 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
    15 hours 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
    15 hours ago














    $begingroup$
    After changing my definition of recursion to work with a symbolic sX, which actually makes evaluations much much faster overall, I can utilise this to get exactly what I need. Thank you all for your help, this is the fastest solution I found.
    $endgroup$
    – Brad
    13 hours ago




    $begingroup$
    After changing my definition of recursion to work with a symbolic sX, which actually makes evaluations much much faster overall, I can utilise this to get exactly what I need. Thank you all for your help, this is the fastest solution I found.
    $endgroup$
    – Brad
    13 hours ago











    7












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


















      7












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
















        7












        7








        7





        $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 14 hours ago

























        answered 14 hours 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

            El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

            Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...

            Castillo d'Acher Características Menú de navegación