title: Prolog: implement Luhn algorithm with efficiency
body: <p>I try to apply Luhn algorithm in SWI-Prolog. But I get some problem in running. When I test with some simple number like 123, it gives out result fast. If I test with longer number like 5379173895860200, it runs so long time that I can only abort this execution. Need help to find problem.
  code:</p>
  
  <pre><code>luhn(N):-
      spliter(N,Y),
      reverse(Y, Z),
      check(Z,X),
      sum_all(X, Res),
      T is Res mod 10,
      T is 0.
  
  spliter(0,[]).
  spliter(N,L):-
      N1 is floor(N/10),
      X is N mod 10,
      spliter(N1, L2),
      L = [X|L2].
  
  check(A,B):-
      double(A,B,_).
  
  double([],[],0).
  double([H|T], [H1|T1], C):-
      double(T,T1, C1),
      C is C1 +1,
      H1 is H*(1+ C mod 2).
  
  sum_all([],0).
  sum_all([H|T],Sum):-
      sum_all(T,Subsum),
      X is floor(H/10),
      Y is H mod 10,
      Sum is (Subsum + X + Y).
  </code></pre>