Wednesday 15 June 2011

integer division operator in Prolog -


This code is a part of the program that I am writing to solve cryptirimetic puzzles in Period. I am resolving it using CLPFD (SICSTUS Prologue). I am getting an error when using the Inbuilt Integer Division operator "//" (see below for details). I was not able to solve it, so I wrote my own integer division function.

What should I know why "//" fail . Other arithmetic operators like +, -, /

BEFORE:

  Hull 1 ([], [], [H], H) . Hull ([H1], [H2], [H3, H4], C): - H1 # \ = 0, H2 = \ = 0, H3 = (C + H1 + H2) Mod 10, H4 = = (C + H + 1 + H2) // 10 Hull ([H1 | T1], [H2 | T2], [H3 | T3], C): - H3 # (C + H + 1H 2) Module 10, C1 # (C + H1 + H 2) // 10, solution (T1, T2, T3, C1).  

This is an error I got

Error: Domain error: clpfd_expression 'expected, found (0 + _G1592 + _G1586) // 10 'exception: (12) throw (error (domain_up (CLPFD_ expression, (0 + _G3994 {0..9} + _ G3991 {0..9}) / 10), _G3976))?

after:

  integer_divid (n, m): - m # = n / 10, integer (m). Integer_div (N, M): - N1 # = N Mod 10, N2 # = N-N1, M # = N2/10 solve1 ([], [], [H], H). Hull ([H1], [H2], [H3, H4], C): - H1 # \ = 0, H2 = \ = 0, H3 = (C + H1 + H2) Mod 10, Integer_div (C + H1 + H2), H4). Hull ([H1 | T1], [H2 | T2], [H3 | T3], c): - H3 # (C + H1 + H2) Mod 10, Integer_div (C + H1 + H2) , C1), solution (T1, T2, T3, C1).  

It works perfectly, "//" was replaced by my own version of the integer division

According to

, CLP-FD uses for integer division.


No comments:

Post a Comment