title: integer division operator in Prolog
body: <p>This code is a part of the program that I am writing to solve a cryptarithmatic puzzle in prolog. I am solving this using CLPFD (SICStus Prolog). I am getting an error while using the inbuilt integer division operator "//" (See Below for details). I was not able to solve this So I wrote my own integer division function.</p>
  
  <p><strong>What I want to know is why "//" fails</strong>. There is no such problem with the other arithmetic operators like +, - , /</p>
  
  <p><strong>BEFORE:</strong></p>
  
  <pre><code>solve1([],[],[H],H).
  solve([H1],[H2],[H3,H4],C) :- H1 #\= 0, H2 #\= 0,
                                H3 #= (C+H1+H2)mod 10,
                                H4 #=(C+H1+H2)//10.
  
  solve([H1|T1] , [H2|T2] , [H3|T3],C) :- H3 #= (C+H1+H2)mod 10,
                                          C1 #=(C+H1+H2)//10 ,
                                          solve(T1,T2,T3,C1).
  </code></pre>
  
  <p>This is the error I get</p>
  
  <p><strong>ERROR:</strong> Domain error: <code>clpfd_expression' expected, found</code>(0+_G1592+_G1586)//10'
  Exception: (12) throw(error(domain_error(clpfd_expression, (0+_G3994{0..9}+_G3991{0..9})//10), _G3976)) ? </p>
  
  <p><strong>AFTER:</strong></p>
  
  <pre><code>integer_div(N,M) :- M #= N/10 , integer(M).
  integer_div(N,M) :- N1 #= N mod 10 , N2 #= N-N1 , M #= N2/10.
  
  
  solve1([],[],[H],H).
  solve([H1],[H2],[H3,H4],C) :- H1 #\= 0, H2 #\= 0,
                                H3 #= (C+H1+H2)mod 10,
                                integer_div((C+H1+H2),H4).
  
  solve([H1|T1] , [H2|T2] , [H3|T3],C) :- H3 #= (C+H1+H2)mod 10,
                                          integer_div((C+H1+H2),C1) ,
                                          solve(T1,T2,T3,C1).
  </code></pre>
  
  <p>This works perfectly All I did was replace "//" by my own version of integer division</p>