title: Prolog: Doubling the value of each element in a list of lists and returning a single list
body: <p>I need write a set of clauses that take a list of integer lists and return a single list with all the elements doubled.</p>
  
  <p>For example:</p>
  
  <pre><code>?- double([[1,2],[3]], X).
  Yes
  X = [2,4,6]
  </code></pre>
  
  <p>I have a set of clauses called mega_append that return a single list from a list of lists.</p>
  
  <p>For example:</p>
  
  <pre><code>?- mega_append([[1,2],[3]], X).
  Yes
  X = [1,2,3]
  </code></pre>
  
  <p>Here is my progress (m_a is short for mega_append):</p>
  
  <pre><code>double([],[]).
  double(List,[H1|T1]) :-
      m_a(List,[H2|T2]),
      H1 is 2 * H2,
      double(T2, T1).
  </code></pre>
  
  <p>I'll try to explain how I thought it would work.  I flatten the first list and split it up into a head and a tail (H2 and T2).  I split the second list into a head and a tail (H1 and T1).  I check to make sure that H1 (the doubled value) is equal to 2 times H2 (the original value).  If it is then I check the rest of the list.  Eventually if they all match correctly I should be left with two empty lists which should match the first clause and return yes.</p>
  
  <p>It works when there is only a single value (for example: <code>double([[1]], X)</code>).  Can anyone offer any insight into what I am doing wrong?  Is my logic or code incorrect?</p>