Mapping a function f[xi_,xj_] over a list x1, …, xn with the i < j restrictionSelectively Mapping over elements in a ListWhy is MapIndexed better than mapping over a range?Mapping a function that assigns values to a list over a different listfunction over list with conditionMapping slots over listsMapping over a piecewise functionMapping a function with levelspec vs. Mapping over a flattened list

Subassembly identification

Can I exit and reenter a UK station while waiting for a connecting train?

Was Switzerland pressured either by Allies or Axis to take part in World War 2 at any time?

Was Hitler exclaiming "Heil Hitler!" himself when saluting?

Automatically creating table with borders

Why can a T* be passed in register, but a unique_ptr<T> cannot?

Convexity of a QP

What is the white stuff emerging from a hole on the surface of Mars?

QGIS 3.6.1 problems with CRS

Modeling the Round (Nearest Integer) function

How do social media apps notify you when someone else takes a screenshot of your profile?

If equal temperament divides octave into 12 equal parts, why hertz differences are not the same but element 12th of two?

For piano scales, should I let go of the previous key before I hit the next one?

Would fantasy dwarves be able to invent and/or manufacture the radio?

What does "he was equally game to slip into bit parts" mean?

Vertical Yagi spun at 1000 RPM: gain properties?

Should I respond to a sabotage accusation e-mail at work?

Are there any Baryons that have quark-antiquark combinations?

In this scene from the novel, 'The Martian', by Andy Weir, how does Mark Watney store hydrogen made from water in the tank?

Why doesn't the nucleus have "nucleus-probability cloud"?

Why not 1.d4 Nf6 2.d5?

Options for passes to national parks in Arizona/Utah for 5 people travelling in one car

RAM stress test

Why didn't Aboriginal Australians discover agriculture?



Mapping a function f[xi_,xj_] over a list x1, …, xn with the i


Selectively Mapping over elements in a ListWhy is MapIndexed better than mapping over a range?Mapping a function that assigns values to a list over a different listfunction over list with conditionMapping slots over listsMapping over a piecewise functionMapping a function with levelspec vs. Mapping over a flattened list






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;

.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;








5














$begingroup$


I am often facing the situation where I have a list $...x_k...$ and where I want to compute:



$$
...f[x_i,x_j]...text with i<j
$$



Unfortunately, I have not been able to find an elegant solution for this problem. What I'm doing right now seems horrible to me (indirections etc...):



n = 4;
x = Table[RandomReal[], n]



0.547984, 0.601967, 0.000917483, 0.738287




Map[f[Apply[Sequence, x[[#]]]] &, 
Flatten[Table[i, j, i, 1, n, j, i + 1, n], 1]]



f[0.547984, 0.601967], f[0.547984, 0.000917483], f[0.547984,
0.738287], f[0.601967, 0.000917483], f[0.601967, 0.738287], f[0.000917483, 0.738287]




(in real situation f is defined f[xi_,xj_]:= xi-xj for instance)



Question: what is a better (builtin?) solution?










share|improve this question












$endgroup$





















    5














    $begingroup$


    I am often facing the situation where I have a list $...x_k...$ and where I want to compute:



    $$
    ...f[x_i,x_j]...text with i<j
    $$



    Unfortunately, I have not been able to find an elegant solution for this problem. What I'm doing right now seems horrible to me (indirections etc...):



    n = 4;
    x = Table[RandomReal[], n]



    0.547984, 0.601967, 0.000917483, 0.738287




    Map[f[Apply[Sequence, x[[#]]]] &, 
    Flatten[Table[i, j, i, 1, n, j, i + 1, n], 1]]



    f[0.547984, 0.601967], f[0.547984, 0.000917483], f[0.547984,
    0.738287], f[0.601967, 0.000917483], f[0.601967, 0.738287], f[0.000917483, 0.738287]




    (in real situation f is defined f[xi_,xj_]:= xi-xj for instance)



    Question: what is a better (builtin?) solution?










    share|improve this question












    $endgroup$

















      5












      5








      5


      1



      $begingroup$


      I am often facing the situation where I have a list $...x_k...$ and where I want to compute:



      $$
      ...f[x_i,x_j]...text with i<j
      $$



      Unfortunately, I have not been able to find an elegant solution for this problem. What I'm doing right now seems horrible to me (indirections etc...):



      n = 4;
      x = Table[RandomReal[], n]



      0.547984, 0.601967, 0.000917483, 0.738287




      Map[f[Apply[Sequence, x[[#]]]] &, 
      Flatten[Table[i, j, i, 1, n, j, i + 1, n], 1]]



      f[0.547984, 0.601967], f[0.547984, 0.000917483], f[0.547984,
      0.738287], f[0.601967, 0.000917483], f[0.601967, 0.738287], f[0.000917483, 0.738287]




      (in real situation f is defined f[xi_,xj_]:= xi-xj for instance)



      Question: what is a better (builtin?) solution?










      share|improve this question












      $endgroup$




      I am often facing the situation where I have a list $...x_k...$ and where I want to compute:



      $$
      ...f[x_i,x_j]...text with i<j
      $$



      Unfortunately, I have not been able to find an elegant solution for this problem. What I'm doing right now seems horrible to me (indirections etc...):



      n = 4;
      x = Table[RandomReal[], n]



      0.547984, 0.601967, 0.000917483, 0.738287




      Map[f[Apply[Sequence, x[[#]]]] &, 
      Flatten[Table[i, j, i, 1, n, j, i + 1, n], 1]]



      f[0.547984, 0.601967], f[0.547984, 0.000917483], f[0.547984,
      0.738287], f[0.601967, 0.000917483], f[0.601967, 0.738287], f[0.000917483, 0.738287]




      (in real situation f is defined f[xi_,xj_]:= xi-xj for instance)



      Question: what is a better (builtin?) solution?







      list-manipulation programming






      share|improve this question
















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 28 at 11:40







      Picaud Vincent

















      asked May 28 at 11:14









      Picaud VincentPicaud Vincent

      1,5827 silver badges18 bronze badges




      1,5827 silver badges18 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          7
















          $begingroup$

          Subsets[f @@ x, 2]



          f[0.817389, 0.11142], f[0.817389, 0.789526], f[0.817389, 0.187803],
          f[0.11142, 0.789526], f[0.11142, 0.187803], f[0.789526, 0.187803]




          You can also use



          f @@@ Subsets[x, 2]
          Join @@ Table[f @@ x[[i, j]], i, 1, n, j, i + 1, n]





          share|improve this answer












          $endgroup$
















            Your Answer








            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/4.0/"u003ecc by-sa 4.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%2f199243%2fmapping-a-function-fxi-xj-over-a-list-x1-xn-with-the-i-j-restrict%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown


























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            7
















            $begingroup$

            Subsets[f @@ x, 2]



            f[0.817389, 0.11142], f[0.817389, 0.789526], f[0.817389, 0.187803],
            f[0.11142, 0.789526], f[0.11142, 0.187803], f[0.789526, 0.187803]




            You can also use



            f @@@ Subsets[x, 2]
            Join @@ Table[f @@ x[[i, j]], i, 1, n, j, i + 1, n]





            share|improve this answer












            $endgroup$



















              7
















              $begingroup$

              Subsets[f @@ x, 2]



              f[0.817389, 0.11142], f[0.817389, 0.789526], f[0.817389, 0.187803],
              f[0.11142, 0.789526], f[0.11142, 0.187803], f[0.789526, 0.187803]




              You can also use



              f @@@ Subsets[x, 2]
              Join @@ Table[f @@ x[[i, j]], i, 1, n, j, i + 1, n]





              share|improve this answer












              $endgroup$

















                7














                7










                7







                $begingroup$

                Subsets[f @@ x, 2]



                f[0.817389, 0.11142], f[0.817389, 0.789526], f[0.817389, 0.187803],
                f[0.11142, 0.789526], f[0.11142, 0.187803], f[0.789526, 0.187803]




                You can also use



                f @@@ Subsets[x, 2]
                Join @@ Table[f @@ x[[i, j]], i, 1, n, j, i + 1, n]





                share|improve this answer












                $endgroup$



                Subsets[f @@ x, 2]



                f[0.817389, 0.11142], f[0.817389, 0.789526], f[0.817389, 0.187803],
                f[0.11142, 0.789526], f[0.11142, 0.187803], f[0.789526, 0.187803]




                You can also use



                f @@@ Subsets[x, 2]
                Join @@ Table[f @@ x[[i, j]], i, 1, n, j, i + 1, n]






                share|improve this answer















                share|improve this answer




                share|improve this answer








                edited May 28 at 11:37

























                answered May 28 at 11:32









                kglrkglr

                221k10 gold badges251 silver badges509 bronze badges




                221k10 gold badges251 silver badges509 bronze badges































                    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%2f199243%2fmapping-a-function-fxi-xj-over-a-list-x1-xn-with-the-i-j-restrict%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

                    Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

                    How to get a smooth, uniform ParametricPlot of a 2D Region?How to plot a complicated Region?How to exclude a region from ParametricPlotHow discretize a region placing vertices on a specific non-uniform gridHow to transform a Plot or a ParametricPlot into a RegionHow can I get a smooth plot of a bounded region?Smooth ParametricPlot3D with RegionFunction?Smooth border of a region ParametricPlotSmooth region boundarySmooth region plot from list of pointsGet minimum y of a certain x in a region

                    Genealogie vun de Merowenger Vum Merowech bis zum Chilperich I. | Navigatiounsmenü