Hi Mark,

there is no bug here. It is your Prolog formulation which is wrong.
E.g. \== does not really work with variables. Try:

| ?- X = foo, X \== foo.

no
| ?- X \== foo, X = foo.

X = foo

yes

So the order of calls is relevant if you use \==. In solve you call fact1 
(which calls \==) before variables have values so \== does not work as you 
expect. 

Daniel

Le 10 juil. 2012 à 18:23, Mark Roulo a écrit :

> 1) The type of machine you are using (use uname -a under Unix).
> 
>    uname -a
>    Darwin Mark-Roulos-MacBook-Pro.local 10.8.0 Darwin Kernel Version 10.8.0: 
> Tue Jun  7 16:32:41 PDT 2011;
>    root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64
> 
> 2) GNU Prolog version (use gprolog --version)
> 
>    gprolog --version
>    Prolog top-Level (GNU Prolog) 1.4.1
>    By Daniel Diaz
>    Copyright (C) 1999-2012 Daniel Diaz
> 
>    GNU Prolog comes with ABSOLUTELY NO WARRANTY.
>    This is free software; see the source or the file
>    named COPYING for copying conditions.
> 
>    NOTE that this also shows up in 1.4.0.
> 
> 3) The operands given to the `configure' and the output of the configuration 
> if the bug concerns the compilation/installation phase.
> 
>    N/A.  The problem is not in the compilation/installation phase.
>    In any event, I used:
>        ./configure
>        make
>        make install
> 
> 4) The complete text of any files needed to reproduce the bug. Try to obtain 
> a minimal example showing the bug.
> 
>    See below
> 
> 5) The precise commands we need to type to reproduce the bug.
> 
>        gprolog --consult-file bug.pl 
> 
>        | ?- solve(S).
> 
>        S = [[andrew,corey,sandy,doru],[doru,corey,andrew,sandy]] ? ;
>   
>        S = [[andrew,sandy,corey,doru],[doru,corey,andrew,sandy]] ? ;
> 
>        S = [[sandy,andrew,corey,doru],[doru,corey,sandy,andrew]] ? ;
> 
>        (1 ms) no
>        | ?- solve2(S).
> 
>        S = [[sandy,andrew,corey,doru],[doru,corey,sandy,andrew]] ? ;
> 
>        (3 ms) no
>        | ?- 
> 
> 6) A description of what behavior you observe that you believe is incorrect.
> 
>      solve and solve2 are identical except for the order of the clauses.
> 
>      I would expect that:
>          (a) The results would be the same (except for order, maybe), and
>          (b) That they would both be correct.
> 
>      solve() gives the wrong result ... the first two results above do not
>      meet all the constraints (see fact1 below).
> 
>      This seems wrong.  On the other hand, I'm still learning Prolog, so it
>      is also possible that the two *should* be different and I just don't know
>      what I'm doing ... :-)
> 
> Regards,
>     -Mark Roulo
> 
> 
> Source for bug.pl
> ================================================================================
> /*   
>     Problem lifted from: 
> http://www.anselm.edu/internet/compsci/Faculty_Staff/mmalita/HOMEPAGE/logic/aa1.txt
> 
>      File: aa1.pl
>      Author: (sol MM)
>      Title: Contest: swimming and biking
>      From: Prof. Adrian Atanasiu: http://www.galaxyng.com/potw/
> 
> Four students competed in two different tests: swimming and biking.
> Can you establish the final order for each test?
> 1. Andrew did not win any competition.
> 2. The person who won the swimming contest was the third 
>    at the bike competition.
> 3. Andrew did better than Corey at the swimming contest,
>    but Corey was better than Andrew at the bike contest.
> 4. Corey was never the last.
> 5. Doru won the bike contest, 
>    but Sandy was better than him at the swimming contest.
> What was the winning order in the swimming and bike contest?
> 
> ?- start,fail.
> Swimming contest=[sandy,andrew,corey,dan]
> Bike contest= [dan,corey,sandy,andrew]
> no
> */
> 
> sets_match([], S) :- length(S,0), !.
> sets_match(S1, S2) :-
>     S1 = [H | T],
>     nth(_, S2, H),         % Can we find H in S2
>     delete(S2, H, S3),     % If so, remove H from S2
>     sets_match(T, S3).     % Do this again on T and S2 - H.
> 
> fact1(Solution) :-                          % Andrew never won
>     Solution = [[A,_,_,_],[B,_,_,_]],
>     A \== andrew,
>     B \== andrew.
> 
> fact2(Solution) :-                          % Winner of swimming was 3rd at 
> biking
>     Solution = [[C,_,_,_],[_,_,C,_]].
> 
> fact3(Solution) :-
>     nth(1, Solution, Swimming),
>     nth(2, Solution, Biking),
> 
>     nth(AS, Swimming, andrew),
>     nth(CS, Swimming, corey),
> 
>     nth(AB, Biking, andrew),
>     nth(CB, Biking, corey),
> 
>     AS < CS,
>     CB < AB.
> 
> fact4(Solution) :-                        % Corey was never last
>     Solution = [[_,_,_,D],[_,_,_,E]],
>     D \== corey,
>     E \== corey.
> 
> fact5(Solution) :-
>     Solution = [Swimming, [doru,_,_,_]],
>     nth(DoruSwimming,  Swimming, doru),
>     nth(SandySwimming, Swimming, sandy),
>     SandySwimming < DoruSwimming.
> 
> no_dups(Solution) :-
>     Solution = [Swimming, Biking],
>     sets_match(Swimming, [doru, sandy, corey, andrew]),
>     sets_match(Biking,   [doru, sandy, corey, andrew]).
> 
> 
> solve2(Solution) :-
>     no_dups(Solution),
>     fact1(Solution),
>     fact2(Solution),
>     fact3(Solution),
>     fact4(Solution),
>     fact5(Solution).
> 
> 
> solve(Solution) :-
>     fact1(Solution),
>     fact2(Solution),
>     fact3(Solution),
>     fact4(Solution),
>     fact5(Solution),
>     no_dups(Solution).
> 
> 
> 
> -- 
> Ce message a été vérifié par MailScanner pour des virus ou des polluriels et 
> rien de suspect n'a été trouvé.
> _______________________________________________
> Bug-prolog mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/bug-prolog


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

_______________________________________________
Bug-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-prolog

Reply via email to