Re: variable analysis

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 08/15/2013 01:18 PM, Carlo Capelli wrote:
> Also my code generates similar warnings
>
> curious_fraction(Nr, Dr) :-
>     Vs = [N1,N2, D1,D2], Vs ins 1..9,
>     N #= N1 * 10 + N2, D #= D1 * 10 + D2, D #> N,
>     select(C, [N1,N2], [Nr]), select(C, [D1,D2], [Dr]),
>     N * Dr #= Nr * D, label(Vs).
>
> generates
>
> Warning: /home/carlo/prolog/coins.pl:129:
>
> Test is always true: var(N)
> Test is always true: var(D)

Clpfd generates redudant code, expecting the compiler to optimize it. I
vaguely knew this. Not really sure how to handle this. You can use

     :- style_check(-no_effect)

to get rid of these. Actually, it traps more in this code, but it is
currently configured to ignore warnings about goals that have no named
variables, assuming these are generated. I guess we either need an
library that can be called to optimize the generated code or we need
some way for term/goal expansion to tell the compiler not to worry about
this code.  Ideas?

	Cheers --- Jan

2 ?- listing(curious_fraction).
curious_fraction(K, M) :-
	A=[B, C, F, G],
	A ins 1..9,
	(   integer(D)
	->  (   var(B*10+C)
	    ->  B*10+C is D
	    ;   integer(B),
		integer(C)
	    ->  D=:=B*10+C
	    ;   E is D,
		clpfd:clpfd_equal(E, B*10+C)
	    )
	;   integer(B),
	    integer(C)
	->  (   var(D)
	    ->  D is B*10+C
	    ;   E is B*10+C,
		clpfd:clpfd_equal(D, E)
	    )
	;   clpfd:clpfd_equal(D, B*10+C)
	),
	(   integer(H)
	->  (   var(F*10+G)
	    ->  F*10+G is H
	    ;   integer(F),
		integer(G)
	    ->  H=:=F*10+G
	    ;   I is H,
		clpfd:clpfd_equal(I, F*10+G)
	    )
	;   integer(F),
	    integer(G)
	->  (   var(H)
	    ->  H is F*10+G
	    ;   I is F*10+G,
		clpfd:clpfd_equal(H, I)
	    )
	;   clpfd:clpfd_equal(H, F*10+G)
	),
	(   integer(H)
	->  (   integer(D)
	    ->  H>=D+1
	    ;   J is H,
		clpfd:clpfd_geq(J, D+1)
	    )
	;   integer(D)
	->  J is D+1,
	    clpfd:clpfd_geq(H, J)
	;   clpfd:clpfd_geq(H, D+1)
	),
	select(L, [B, C], [K]),
	select(L, [F, G], [M]),
	(   integer(D),
	    integer(M)
	->  (   var(K*H)
	    ->  K*H is D*M
	    ;   integer(K),
		integer(H)
	    ->  D*M=:=K*H
	    ;   N is D*M,
		clpfd:clpfd_equal(N, K*H)
	    )
	;   integer(K),
	    integer(H)
	->  (   var(D*M)
	    ->  D*M is K*H
	    ;   N is K*H,
		clpfd:clpfd_equal(D*M, N)
	    )
	;   clpfd:clpfd_equal(D*M, K*H)
	),
	label(A).


> OT: Jan, the jump to source origin of message now make difficult to select
> the text, I will try to fix it...

Making progress ... I have a working MacOS swipl-win.app (well,
proof of concept).

	Cheers --- Jan

>
> bye Carlo
> -------------- next part --------------
> HTML attachment scrubbed and removed
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
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.