Re: negative numbers

michel levy <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Alexandre Saidi wrote:
> Hello all,
> I know that Gprolog does not handle negative intergers.
> 
> However, someone could tell me why gprolog rejects vilently this :
> 
> ?- fd_domain(I,1,4), fd_element(I,[12, 5, -7,9], X).
> 
> Fatal Error: Segmentation Violation
> 
> Ok, she does not like my -7.
> 
> But with :
> X #= -1.
> I get just (gently)
> no.
> 
> PS : the original resuest was :
> ?- fd_domain([S1, S2], 1, 7), S1 #=S2 +X, fd_domain(I,1,4), 
> fd_element(I,[-1,-2,1,2], X), fd_labeling([S1,S2]).
> 
> I'm trying to get S1 and S2 (2 days of a week) being two consecutive 
> days or with a difference of 2 .
> An elegant way to this in gprolog (a  short one is wellcome : I'm trying 
> to illustratre CLP power in an introduction).
> 
> Thanks.
> Alex
> 
> _______________________________________________
> Users-prolog mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/users-prolog
Les variables à domaine finis sont des entiers positifs ou nuls.
Donc en posant cette requête, vous contraignez X à être positif et négatif.

The FD variables are positive or nul integers.
Your request fd_element(I,[12, 5, -7,9], X) constrains X to be positive 
and negative : I am not surprised by this segmentation violation, but in 
the gprolog manual (8.8.2) this case is not referenced.


Another example :
[michel@localhost ~]$ gprolog
GNU Prolog 1.2.19
By Daniel Diaz
Copyright (C) 1999-2005 Daniel Diaz
| ?- fd_element(1,[-1],X).
Fatal Error: Segmentation Violation

But
| ?- fd_element_var(1,[-1],X).
no

And now let's return to your example
| ?- fd_element_var(I,[12, 5, -7,9], X).
I = _#3(1..2:4)
X = _#71(5:9:12)
yes
| ?- fd_element(I,[12, 5, -7,9], X).
Fatal Error: Segmentation Violation




-- 
Michel Levy
36 rue George Sand
38400 Saint Martin d'Heres
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.