title: Finding all possible Combination of Pairs in a list
body: <p>I am experimenting with the implementation of Integration by parts and am trying to pull out all the possible <code>u</code> and <code>dv</code> pairs from a list of all the things multiplied together. The code provided is my method, except the Function objects have been replaced with strings for readability and so that people could run it out of context.</p>
  
  <pre><code>ArrayList&lt;String&gt; funcObjects = giveList(CALC.MULTIPLY, function);//populate this any way you like
  
  //all the pairs are stored in a matrix
  int pairCounter = 0;
  String[][] udvPairs = new String[funcObjects.size() * funcObjects.size()][2];
  //for (int skip = 0; skip &lt; 1; skip++) {
  //commented out for sake of a better solution
  for (int i = 0; i &lt; funcObjects.size() - 1; i++) {
      System.out.println("i=" + i);
      //System.out.println(function.size());
      for (int j = 0; j &lt; funcObjects.size() - i; j++) {
          System.out.println("j=" + j);
          CalcObject u = "1";
          CalcObject dv = "1";
          for (int start = j; start &lt;= j + i; start++) {
              //this loop here is what is generating my u.
              //note that it goes in order and therefore cannot
              //account for items that are not next to each other in the list
              //my question is how to add a fix for this
              u = u + " * " + funcObjects.get(start);
          }
          for (int end = 0; end &lt; j; end++) {
              dv = dv + " * " + funcObjects.get(end);
          }
          for (int end = j + i + 1; end &lt; funcObjects.size(); end++) {
              dv = dv + " * " + funcObjects.get(end);
          }
  
          System.out.println("Pair " + pairCounter + "; u: " + u.toString() + " dv: " + dv.toString());
          udvPairs[pairCounter][0] = u;
          udvPairs[pairCounter][1] = dv;
          pairCounter++;
      }
  }
  </code></pre>
  
  <p>This is my code so far. The combinations it gives me are correct, but it does not give me all the combinations. For example:</p>
  
  <p><code>x * SIN(x) * COS(x)</code></p>
  
  <p>i.e. the list passed in being <code>["x","SIN(x)","COS(x)"]</code></p>
  
  <p>will give me</p>
  
  <pre><code>i=0  
  j=0  
  Pair 0; u: x dv: SIN(x) * COS(x)  
  j=1   
  Pair 1; u: SIN(x) dv: x * COS(x)  
  j=2  
  Pair 2; u: COS(x) dv: x * SIN(x)  
  i=1  
  j=0  
  Pair 3; u: x * SIN(x) dv: COS(x)  
  j=1  
  Pair 4; u: SIN(x) * COS(x) dv: x  
  </code></pre>
  
  <p>It is skipping u: <code>x * COS(x) dv: SIN(x)</code></p>
  
  <p>So my question is, anyone have an idea how to make it also account for combinations in which the parts are not next to each other? The program is not throwing any errors, I just don't know how to finish implementing what I need.</p>
  
  <p>Thanks.</p>