Strange variables...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange variables...

Fred Bapst-2
I'm observing a rather strange behaviour (GnuProlog 1.4.4 on Windows and Linux,
idem for older versions) and I'm not able to completely isolate it; it seems to
be related to singleton variables and backtracking. Here is a stupid code
demonstrating the issue:

%--------------
z(A,B, A,B).
z(A,B, B,A).

p5(Ls):-
    _ = [B, C],
    % write(B), % write(C),
    Ls = [A, E],
    z(A, _, 1, 2),
    E=3,
    z(A, _, B, C).

%--------------

Asking for every solution leads to an infinite loop...

  ?- p5(X).
  X = [1,3] ? a
     ...... [infinine loop].....

Writing B and C removes the problem; and writing only one of them leads to
another strange behavior.

Running the call with the tracer also changes the behavior, and reveals
strange d(...) sub-terms:

{trace}
| ?- p5(X).
      1    1  Call: p5(_23) ?
      2    2  Call: z(_53,_57,1,2) ?
      2    2  Exit: z(1,2,1,2) ?
      3    2  Call: z(1,_85,_126,_127) ?
      3    2  Exit: z(1,_85,1,_85) ?
      1    1  Exit: p5([1,3]) ?
X = [1,3] ? a
      1    1  Redo: p5([1,3]) ?
      3    2  Redo: z(1,_85,1,_85) ?
      3    2  Exit: z(1,_85,_85,1) ?
      1    1  Exit: p5([1,3]) ?
X = [1,3]
      1    1  Redo: p5([1,3]) ?
      2    2  Redo: z(1,2,1,2) ?
      2    2  Exit: z(2,1,1,2) ?
      3    2  Call:
z(2,_85,d(3,[a(z(2,_85,d(3,[a(z(2,_85,...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
?
      3    2  Exit:
z(2,d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
?
      1    1  Exit: p5([2,3]) ?
X = [2,3]
(16 ms) yes
{trace}


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Strange variables...

Salvador Pinto Abreu
while not really a solution to your problem, a workaround is to use the compiler (ie. gplc) instead of consulting.
you don't get debugging but performance is way better.

21:13:32$ gplc -o xx xx.pl
21:13:38$ ./xx
GNU Prolog 1.4.4 (64 bits)
Compiled Aug 27 2014, 09:59:03 with gcc
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?- p5(X).

X = [1,3] ? a

X = [1,3]

X = [2,3]

X = [2,3]

yes
| ?-


> On 08 Jan 2015, at 19h57, Fred Bapst <[hidden email]> wrote:
>
> I'm observing a rather strange behaviour (GnuProlog 1.4.4 on Windows and Linux,
> idem for older versions) and I'm not able to completely isolate it; it seems to
> be related to singleton variables and backtracking. Here is a stupid code
> demonstrating the issue:
>
> %--------------
> z(A,B, A,B).
> z(A,B, B,A).
>
> p5(Ls):-
>    _ = [B, C],
>    % write(B), % write(C),
>    Ls = [A, E],
>    z(A, _, 1, 2),
>    E=3,
>    z(A, _, B, C).
>
> %--------------
>
> Asking for every solution leads to an infinite loop...
>
>  ?- p5(X).
>  X = [1,3] ? a
>     ...... [infinine loop].....
>
> Writing B and C removes the problem; and writing only one of them leads to
> another strange behavior.
>
> Running the call with the tracer also changes the behavior, and reveals
> strange d(...) sub-terms:
>
> {trace}
> | ?- p5(X).
>      1    1  Call: p5(_23) ?
>      2    2  Call: z(_53,_57,1,2) ?
>      2    2  Exit: z(1,2,1,2) ?
>      3    2  Call: z(1,_85,_126,_127) ?
>      3    2  Exit: z(1,_85,1,_85) ?
>      1    1  Exit: p5([1,3]) ?
> X = [1,3] ? a
>      1    1  Redo: p5([1,3]) ?
>      3    2  Redo: z(1,_85,1,_85) ?
>      3    2  Exit: z(1,_85,_85,1) ?
>      1    1  Exit: p5([1,3]) ?
> X = [1,3]
>      1    1  Redo: p5([1,3]) ?
>      2    2  Redo: z(1,2,1,2) ?
>      2    2  Exit: z(2,1,1,2) ?
>      3    2  Call:
> z(2,_85,d(3,[a(z(2,_85,d(3,[a(z(2,_85,...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
> ?
>      3    2  Exit:
> z(2,d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
> ?
>      1    1  Exit: p5([2,3]) ?
> X = [2,3]
> (16 ms) yes
> {trace}
>
>
> _______________________________________________
> Users-prolog mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/users-prolog


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: Strange variables...

Daniel Diaz-3
In reply to this post by Fred Bapst-2
Hi Fred,

thank you for this report. This is a bug in the compiler.
Fixed in the git and will be available in the 1.4.5 version.

Daniel


Le 08/01/2015 20:57, Fred Bapst a écrit :

> I'm observing a rather strange behaviour (GnuProlog 1.4.4 on Windows and Linux,
> idem for older versions) and I'm not able to completely isolate it; it seems to
> be related to singleton variables and backtracking. Here is a stupid code
> demonstrating the issue:
>
> %--------------
> z(A,B, A,B).
> z(A,B, B,A).
>
> p5(Ls):-
>      _ = [B, C],
>      % write(B), % write(C),
>      Ls = [A, E],
>      z(A, _, 1, 2),
>      E=3,
>      z(A, _, B, C).
>
> %--------------
>
> Asking for every solution leads to an infinite loop...
>
>    ?- p5(X).
>    X = [1,3] ? a
>       ...... [infinine loop].....
>
> Writing B and C removes the problem; and writing only one of them leads to
> another strange behavior.
>
> Running the call with the tracer also changes the behavior, and reveals
> strange d(...) sub-terms:
>
> {trace}
> | ?- p5(X).
>        1    1  Call: p5(_23) ?
>        2    2  Call: z(_53,_57,1,2) ?
>        2    2  Exit: z(1,2,1,2) ?
>        3    2  Call: z(1,_85,_126,_127) ?
>        3    2  Exit: z(1,_85,1,_85) ?
>        1    1  Exit: p5([1,3]) ?
> X = [1,3] ? a
>        1    1  Redo: p5([1,3]) ?
>        3    2  Redo: z(1,_85,1,_85) ?
>        3    2  Exit: z(1,_85,_85,1) ?
>        1    1  Exit: p5([1,3]) ?
> X = [1,3]
>        1    1  Redo: p5([1,3]) ?
>        2    2  Redo: z(1,2,1,2) ?
>        2    2  Exit: z(2,1,1,2) ?
>        3    2  Call:
> z(2,_85,d(3,[a(z(2,_85,d(3,[a(z(2,_85,...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
> ?
>        3    2  Exit:
> z(2,d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),d(3,[a(z(2,d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),d(3,[a(z(2,d(...,...),...),3,2,...),a(p5(...),1,...)]),2),3,2,144),a(p5([2,3]),1,1,87)]),2)
> ?
>        1    1  Exit: p5([2,3]) ?
> X = [2,3]
> (16 ms) yes
> {trace}
>
>
> _______________________________________________
> Users-prolog mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/users-prolog
>


--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog