title: How to simplify algebra equations represented as list of list
body: <p>With Prolog I want to simplify <a href="https://en.wikipedia.org/wiki/Algebraic_expression" rel="nofollow noreferrer">algebra expression</a> represented as as list of list:</p>
  
  <p>algebra equation</p>
  
  <pre><code>f = 3x+2
  </code></pre>
  
  <p>list of list</p>
  
  <pre><code>[[3,1],[2,0]]
  </code></pre>
  
  <p><code>3</code> and <code>2</code> are coefficients<br>
  <code>1</code> and <code>0</code> are exponents  </p>
  
  <p>That should be obvious.</p>
  
  <p>I am looking for some tips or suggestions on how to code the simplifications for this example:</p>
  
  <pre><code>f = 3x+2x+1+2
  [[3,1],[2,1],[1,0],[2,0]]
  </code></pre>
  
  <p>simplified:</p>
  
  <pre><code>f = 5x+3
  [[5,1],[3,0]]
  </code></pre>
  
  <p>I have tried some built in functions but did not get the proper idea about how to use them.</p>