Re: A bug?

From: Joachim Schimpf <j.schimpf_at_icparc.ic.ac.uk>
Date: Fri 28 Sep 2001 12:42:48 PM GMT
Message-ID: <3BB47048.380768E7@icparc.ic.ac.uk>
Anthony Karageorgos wrote:
> 
> Hi all,
> 
> I am attaching an example of a problem I met recently. After obtaining all
> the possible solutions by backtracking I still get the message: 'More (0.00s
> cpu)'
> 
> When I select 'More' then ECLiPSe crashes.
> 
> ------------------------------------
> test_n1(N,X) :-
>     test_n(N,X),
>     labeling(X).
> 
> test_n(0,[]).
> test_n(Sum,[Xo|XRest]) :-
>       Xo :: 1..5,
>       Sum1 #= Sum - Xo,
>       test_n(Sum1,XRest).
> 
> ------------------------------------
> 
> Could anyone tell me where the problem is?


Your program goes into an infinite loop and overflows
memory because you have forgotten to say that Sum
must be positive. Use the tracer to see what happens:

[eclipse 6]: spy test_n.
spypoint added to test_n/2.
Debugger switched on - leap mode

Yes (0.00s cpu)
[eclipse 7]: test_n1(2,X).
 +(2) 2 CALL  test_n(2, X)   %> leap
 +(9) 3 CALL  test_n(Sum1{[-3..1]}, XRest)   %> leap
 +(9) 3 *EXIT  test_n(0, [])   %> leap
 +(2) 2 *EXIT  test_n(2, [2])   %> leap

X = [2]
More (0.00s cpu) ? ;
 +(2) 2 REDO  test_n(2, [Xo{[... .. ...]}|XRest])   %> leap
 +(9) 3 REDO  test_n(Sum1{[-3..1]}, XRest)   %> leap
 +(29) 4 CALL  test_n(Sum1{[-8..0]}, XRest)   %> leap
 +(29) 4 *EXIT  test_n(0, [])   %> leap
 +(9) 3 *EXIT  test_n(1, [1])   %> leap
 +(2) 2 *EXIT  test_n(2, [1, 1])   %> leap

X = [1, 1]
More (0.00s cpu) ? ;
 +(2) 2 REDO  test_n(2, [Xo{[... .. ...]}, Xo{[...]}|XRest])   %> leap
 +(9) 3 REDO  test_n(Sum1{[-3..1]}, [Xo{[... .. ...]}|XRest])   %> leap
 +(29) 4 REDO  test_n(Sum1{[-8..0]}, XRest)   %> leap
 +(60) 5 CALL  test_n(Sum1{[-13..-1]}, XRest)   %> leap
 +(60) 5 NEXT  test_n(Sum1{[-13..-1]}, XRest)   %> leap
 +(69) 6 CALL  test_n(Sum1{[-18..-2]}, XRest)   %> leap
 +(69) 6 NEXT  test_n(Sum1{[-18..-2]}, XRest)   %> leap
 +(78) 7 CALL  test_n(Sum1{[-23..-3]}, XRest)   %> leap
 +(78) 7 NEXT  test_n(Sum1{[-23..-3]}, XRest)   %> leap
 +(87) 8 CALL  test_n(Sum1{[-28..-4]}, XRest)   %> leap
 +(87) 8 NEXT  test_n(Sum1{[-28..-4]}, XRest)   %> leap
 +(96) 9 CALL  test_n(Sum1{[-33..-5]}, XRest)   %> leap
...


The following works:

test_n(0,[]).
test_n(Sum,[Xo|XRest]) :-
      Sum #>= 0,		% add this line
      Xo :: 1..5,
      Sum1 #= Sum - Xo,
      test_n(Sum1,XRest).


-- 
 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc, Imperial College   /            mailto:J.Schimpf@ic.ac.uk
 London SW7 2AZ, UK         /    http://www.icparc.ic.ac.uk/eclipse
Received on Fri Sep 28 13:42:58 2001

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:10 PM GMT GMT