0

I tested the following code by adding it to the user file in swipl, gprolog, and yap:

isqrt(N, _) :-
    N < 0, !, fail. 
isqrt(N, N) :-
    N < 2.
isqrt(N, R) :-
    X is N,
    Y is (N // 2),
    isqrt(N, X, Y, R).

isqrt(_, X, Y, X) :- 
    Y >= X.
isqrt(N, _, Y, R) :-
    Z is ((Y + N // Y) // 2),
    isqrt(N, Y, Z, R).

This works as expected in swipl and yap, but in gprolog I get the following error message for N > 1:

uncaught exception: error(existence_error(procedure,isqrt/0),isqrt/0)

This is strange to me because none of the predicates in my code rely on isqrt/0. Could this be a bug in GNU-Prolog? What can I do to as a workaround?


Edit: Here's exactly what I do to produce this error in gprolog on ubuntu:

$ gprolog
GNU Prolog 1.4.5 (64 bits)
Compiled Feb  5 2017, 10:30:08 with gcc
By Daniel Diaz
Copyright (C) 1999-2016 Daniel Diaz
| ?- [user].
compiling user for byte code...
isqrt(N, _) :-
    N < 0, !, fail. 

isqrt(N, N) :-
    N < 2.

isqrt(N, R) :-
    X is N,
    Y is (N // 2),
    isqrt(N, X, Y, R).

isqrt(_, X, Y, X) :- 
    Y >= X.

isqrt(N, _, Y, R) :-
    Z is ((Y + N // Y) // 2),
    isqrt(N, Y, Z, R).

user compiled, 17 lines read - 1656 bytes written, 10751 ms

yes
| ?- isqrt(100, X).
uncaught exception: error(existence_error(procedure,isqrt/0),isqrt/0)
false
  • 10,264
  • 13
  • 101
  • 209
castle-bravo
  • 1,389
  • 15
  • 34
  • I'm unable to reproduce the error using GNU Prolog 1.4.5. – Paulo Moura Dec 09 '18 at 08:21
  • @PauloMoura, thanks for trying. I've updated my question to show precisely what I do to reproduce this error. I am also using version 1.4.5. – castle-bravo Dec 09 '18 at 16:06
  • I'm on macOS. Most likely there's some GNU Prolog build issue. Did you compile it from sources or used some binary installer? – Paulo Moura Dec 09 '18 at 16:29
  • 1
    @PauloMoura, I downloaded it direct from the ubuntu 18.04 software repositories. I'll build it from source and see if I have the same issue. Thanks for the tip! – castle-bravo Dec 09 '18 at 17:11
  • 1
    @PauloMoura, I built and installed gprolog from source and everything works fine now. Thanks again. If you write up your comment as a short answer, I will select it as the correct one. – castle-bravo Dec 09 '18 at 17:20

1 Answers1

1

There have been some reports, including in the GNU Prolog mailing list, of similar errors under Linux, notably Ubuntu/kubuntu:

http://lists.gnu.org/archive/html/bug-prolog/2018-09/msg00002.html

In the report cases, compiling GNU Prolog from the sources solved the problem.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33