Nooby stumped by effect of repeated rule

This is a discussion on Nooby stumped by effect of repeated rule within the lisp forums in Programming Languages category; Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to be precise) in case anything looks odd. Given: (<-- (gcf ?x ?y ?f) (is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg (<-- (> ?x ?y) (lispp (> ?x ?y))) ;; some more embedded Lisp Applying the above, we test a hardcoded pair (12 1nd 15) to see if they have gcf > 1: (?- (gcf 15 12 ?x) (= ?x ?y) (> ?y 1)) ?X = 3 ?Y = 3 No. Fine. But now: (?- (gcf 15 12 ?x) (= ?x ?y) ...

Go Back   Application Development Forum > Programming Languages > lisp

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 01-16-2008, 12:39 PM
Ken Tilton
Guest
 
Default Nooby stumped by effect of repeated rule

Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to
be precise) in case anything looks odd.

Given:

(<-- (gcf ?x ?y ?f)
(is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg

(<-- (> ?x ?y)
(lispp (> ?x ?y))) ;; some more embedded Lisp

Applying the above, we test a hardcoded pair (12 1nd 15) to see if they
have gcf > 1:

(?- (gcf 15 12 ?x)
(= ?x ?y)
(> ?y 1))

?X = 3
?Y = 3

No.

Fine. But now:

(?- (gcf 15 12 ?x)
(= ?x ?y)
(> ?y 1)
(= ?x ?y))

No.

The duplication of the line (in the real world case from which this was
distilled) was inadvertent and has been corrected, but I am still
curious as to why it causes the rule to fail. Is this proper Prolog, or
should I make a bug report to the vendor?

kt

ps. duh, it just occurred to me to grab a prolog somewhere and try
something similar in pure prolog. will do. kt


--
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
in the evening, die content!"
-- Confucius
Reply With Quote
  #2  
Old 01-16-2008, 01:06 PM
Chip Eastham
Guest
 
Default Re: Nooby stumped by effect of repeated rule

On Jan 16, 12:39 pm, Ken Tilton <kennytil...@optonline.net> wrote:
> Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to
> be precise) in case anything looks odd.
>
> Given:
>
> (<-- (gcf ?x ?y ?f)
> (is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg
>
> (<-- (> ?x ?y)
> (lispp (> ?x ?y))) ;; some more embedded Lisp
>
> Applying the above, we test a hardcoded pair (12 1nd 15) to see if they
> have gcf > 1:
>
> (?- (gcf 15 12 ?x)
> (= ?x ?y)
> (> ?y 1))
>
> ?X = 3
> ?Y = 3
>
> No.
>
> Fine. But now:
>
> (?- (gcf 15 12 ?x)
> (= ?x ?y)
> (> ?y 1)
> (= ?x ?y))
>
> No.
>
> The duplication of the line (in the real world case from which this was
> distilled) was inadvertent and has been corrected, but I am still
> curious as to why it causes the rule to fail. Is this proper Prolog, or
> should I make a bug report to the vendor?
>
> kt
>
> ps. duh, it just occurred to me to grab a prolog somewhere and try
> something similar in pure prolog. will do. kt
>
> --http://www.theoryyalgebra.com/
>
> "In the morning, hear the Way;
> in the evening, die content!"
> -- Confucius


It looks like a bug to me. I'd try to simplify
the test case before submitting it to the vendor.
In particular, if the failure can be elicited
without making any call to a user-defined goal
such as "gcf", then it becomes easier for the
vendor to duplicate the problem and resolve.

regards, chip
Reply With Quote
  #3  
Old 01-16-2008, 01:20 PM
Ken Tilton
Guest
 
Default Re: Nooby stumped by effect of repeated rule



Chip Eastham wrote:
> On Jan 16, 12:39 pm, Ken Tilton <kennytil...@optonline.net> wrote:
>
>>Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to
>>be precise) in case anything looks odd.
>>
>>Given:
>>
>>(<-- (gcf ?x ?y ?f)
>> (is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg
>>
>>(<-- (> ?x ?y)
>> (lispp (> ?x ?y))) ;; some more embedded Lisp
>>
>>Applying the above, we test a hardcoded pair (12 1nd 15) to see if they
>>have gcf > 1:
>>
>>(?- (gcf 15 12 ?x)
>> (= ?x ?y)
>> (> ?y 1))
>>
>>?X = 3
>>?Y = 3
>>
>>No.
>>
>>Fine. But now:
>>
>>(?- (gcf 15 12 ?x)
>> (= ?x ?y)
>> (> ?y 1)
>> (= ?x ?y))
>>
>>No.
>>
>>The duplication of the line (in the real world case from which this was
>>distilled) was inadvertent and has been corrected, but I am still
>>curious as to why it causes the rule to fail. Is this proper Prolog, or
>>should I make a bug report to the vendor?
>>
>>kt
>>
>>ps. duh, it just occurred to me to grab a prolog somewhere and try
>>something similar in pure prolog. will do. kt
>>
>>--http://www.theoryyalgebra.com/
>>
>>"In the morning, hear the Way;
>> in the evening, die content!"
>> -- Confucius

>
>
> It looks like a bug to me. I'd try to simplify
> the test case before submitting it to the vendor.
> In particular, if the failure can be elicited
> without making any call to a user-defined goal
> such as "gcf", then it becomes easier for the
> vendor to duplicate the problem and resolve.
>
> regards, chip


OK, I'll submit an IR.

That gcf /is/ necessary, or at least simply starting with:

(= ?x 3)

....makes everything work as expected.

thx, kt

--
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
in the evening, die content!"
-- Confucius
Reply With Quote
  #4  
Old 01-16-2008, 01:24 PM
Mark Tarver
Guest
 
Default Re: Nooby stumped by effect of repeated rule

On 16 Jan, 17:39, Ken Tilton <kennytil...@optonline.net> wrote:
> Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to
> be precise) in case anything looks odd.
>
> Given:
>
> (<-- (gcf ?x ?y ?f)
> * *(is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg
>
> (<-- (> ?x ?y)
> * *(lispp (> ?x ?y))) ;; some more embedded Lisp
>
> Applying the above, we test a hardcoded pair (12 1nd 15) to see if they
> have gcf > 1:
>
> (?- (gcf 15 12 ?x)
> * *(= ?x ?y)
> * *(> ?y 1))
>
> ?X = 3
> ?Y = 3
>
> No.
>
> Fine. But now:
>
> (?- (gcf 15 12 ?x)
> * *(= ?x ?y)
> * *(> ?y 1)
> * *(= ?x ?y))
>
> No.
>
> The duplication of the line (in the real world case from which this was
> distilled) was inadvertent and has been corrected, but I am still
> curious as to why it causes the rule to fail. Is this proper Prolog, or
> should I make a bug report to the vendor?
>
> kt
>
> ps. duh, it just occurred to me to grab a prolog somewhere and try
> something similar in pure prolog. will do. kt
>
> --http://www.theoryyalgebra.com/
>
> "In the morning, hear the Way;
> * in the evening, die content!"
> * * * * * * * * * * *-- Confucius



This is what I get under Qi Prolog.

Qi 2007, Copyright (C) 2001-2007 Mark Tarver
www.lambdassociates.org
version 9.0 (Turbo-E)

(0-) (defprolog

"gcf(X,Y,F) :- is(F, (gcd X Y)).
gter(X, Y) :- when((> X Y)).

kenny(X) :- gcf(15,12,X), =(X,Y), gter(Y,1), =(X,Y).")
[gcf* gter* kenny*]

(1-) (define gcd
X Y -> (GCD X Y))
======> Warning:
the following variables are free in gcd: GCD;
gcd

(2-) (ask [kenny X])

X = 3

More? (y/n) y

run time 0 seconds
5 logical inferences
infinite LIPS
false

Mark
Reply With Quote
  #5  
Old 01-16-2008, 02:32 PM
Paul Tarvydas
Guest
 
Default Re: Nooby stumped by effect of repeated rule

I've got a debugged version of PAIP (if you want it, ask me ; also, I have
an alpha version of a WAM written in CL patterned closely on Hassan
Ait-Kaci's tutorial, if someone wants to continue debugging it...).

To (begin to) answer your question, here is what my PAIP compiles your
top-level queries to:


This:
(?- (gcf 15 12 ?x) (= ?x ?y) (>> ?y 1))

compiles to:

(DEFUN TOP-LEVEL-QUERY/0 (CONT)
(LET ((?X (?)))
(GCF/3 '15
'12
?X
#'(LAMBDA ()
(>>/2 ?X '1 #'(LAMBDA () (SHOW-PROLOG-VARS/2 '("?X" "?Y")
(LIST ?X ?X) CONT)))))))


While this:

(?- (gcf 15 12 ?x) (= ?x ?y) (>> ?y 1) (= ?x ?y))

compiles to:

(DEFUN TOP-LEVEL-QUERY/0 (CONT)
(LET ((?X (?))) (GCF/3 '15 '12 ?X #'(LAMBDA () (>>/2 ?X '1 #'(LAMBDA ()
NIL))))))

I.E. the PAIP compiler 'optimizes' the second query to fail.

Likewise:
(?- (= ?x ?y) (= ?x ?y))

compiles to:
(DEFUN TOP-LEVEL-QUERY/0 (CONT) NIL)

Why? I don't know, yet...

pt

Reply With Quote
  #6  
Old 01-16-2008, 02:50 PM
Ken Tilton
Guest
 
Default Re: Nooby stumped by effect of repeated rule



Mark Tarver wrote:
> On 16 Jan, 17:39, Ken Tilton <kennytil...@optonline.net> wrote:
>
>>Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to
>>be precise) in case anything looks odd.
>>
>>Given:
>>
>>(<-- (gcf ?x ?y ?f)
>> (is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg
>>
>>(<-- (> ?x ?y)
>> (lispp (> ?x ?y))) ;; some more embedded Lisp
>>
>>Applying the above, we test a hardcoded pair (12 1nd 15) to see if they
>>have gcf > 1:
>>
>>(?- (gcf 15 12 ?x)
>> (= ?x ?y)
>> (> ?y 1))
>>
>>?X = 3
>>?Y = 3
>>
>>No.
>>
>>Fine. But now:
>>
>>(?- (gcf 15 12 ?x)
>> (= ?x ?y)
>> (> ?y 1)
>> (= ?x ?y))
>>
>>No.
>>
>>The duplication of the line (in the real world case from which this was
>>distilled) was inadvertent and has been corrected, but I am still
>>curious as to why it causes the rule to fail. Is this proper Prolog, or
>>should I make a bug report to the vendor?
>>
>>kt
>>
>>ps. duh, it just occurred to me to grab a prolog somewhere and try
>>something similar in pure prolog. will do. kt
>>
>>--http://www.theoryyalgebra.com/
>>
>>"In the morning, hear the Way;
>> in the evening, die content!"
>> -- Confucius

>
>
>
> This is what I get under Qi Prolog.
>
> Qi 2007, Copyright (C) 2001-2007 Mark Tarver
> www.lambdassociates.org
> version 9.0 (Turbo-E)
>
> (0-) (defprolog
>
> "gcf(X,Y,F) :- is(F, (gcd X Y)).
> gter(X, Y) :- when((> X Y)).
>
> kenny(X) :- gcf(15,12,X), =(X,Y), gter(Y,1), =(X,Y).")
> [gcf* gter* kenny*]
>
> (1-) (define gcd
> X Y -> (GCD X Y))
> ======> Warning:
> the following variables are free in gcd: GCD;
> gcd
>
> (2-) (ask [kenny X])
>
> X = 3
>
> More? (y/n) y
>
> run time 0 seconds
> 5 logical inferences
> infinite LIPS
> false


Thanks. A little leashing indicates the second occurrence of (= ?x ?y)
causes (as best my poor understanding of Prolog allows) ACL Prolog to go
looking for a second value to bind to ?x, so I see it backtracing into
gcf and then failing... why is that? gcf (now) looks like this:

(<-- (gcf ?x ?y ?f)
(lisp ?f (gcd ?x ?y)))

That is a little more succinct than the original, with no effect on the
issue at hand. All invocations have ?x and ?y bound and ?f unbound.
Seems to me the next clause should always be able to bind ?f.

back to the doc....


kt


--
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
in the evening, die content!"
-- Confucius
Reply With Quote
  #7  
Old 01-16-2008, 03:05 PM
Mark Tarver
Guest
 
Default Re: Nooby stumped by effect of repeated rule

On 16 Jan, 19:50, Ken Tilton <kennytil...@optonline.net> wrote:
> Mark Tarver wrote:
> > On 16 Jan, 17:39, Ken Tilton <kennytil...@optonline.net> wrote:

>
> >>Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to
> >>be precise) in case anything looks odd.

>
> >>Given:

>
> >>(<-- (gcf ?x ?y ?f)
> >> * (is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg

>
> >>(<-- (> ?x ?y)
> >> * (lispp (> ?x ?y))) ;; some more embedded Lisp

>
> >>Applying the above, we test a hardcoded pair (12 1nd 15) to see if they
> >>have gcf > 1:

>
> >>(?- (gcf 15 12 ?x)
> >> * (= ?x ?y)
> >> * (> ?y 1))

>
> >>?X = 3
> >>?Y = 3

>
> >>No.

>
> >>Fine. But now:

>
> >>(?- (gcf 15 12 ?x)
> >> * (= ?x ?y)
> >> * (> ?y 1)
> >> * (= ?x ?y))

>
> >>No.

>
> >>The duplication of the line (in the real world case from which this was
> >>distilled) was inadvertent and has been corrected, but I am still
> >>curious as to why it causes the rule to fail. Is this proper Prolog, or
> >>should I make a bug report to the vendor?

>
> >>kt

>
> >>ps. duh, it just occurred to me to grab a prolog somewhere and try
> >>something similar in pure prolog. will do. kt

>
> >>--http://www.theoryyalgebra.com/

>
> >>"In the morning, hear the Way;
> >> *in the evening, die content!"
> >> * * * * * * * * * * -- Confucius

>
> > This is what I get under Qi Prolog.

>
> > Qi 2007, Copyright (C) 2001-2007 Mark Tarver
> >www.lambdassociates.org
> > version 9.0 (Turbo-E)

>
> > (0-) *(defprolog

>
> > * "gcf(X,Y,F) :- is(F, (gcd X Y)).
> > * *gter(X, Y) :- when((> X Y)).

>
> > * *kenny(X) :- gcf(15,12,X), =(X,Y), gter(Y,1), =(X,Y).")
> > [gcf* gter* kenny*]

>
> > (1-) *(define gcd
> > * *X Y -> (GCD X Y))
> > ======> Warning:
> > the following variables are free in gcd: GCD;
> > gcd

>
> > (2-) (ask [kenny X])

>
> > X = 3

>
> > More? (y/n) y

>
> > run time 0 seconds
> > 5 logical inferences
> > infinite LIPS
> > false

>
> Thanks. A little leashing indicates the second occurrence of (= ?x ?y)
> causes (as best my poor understanding of Prolog allows) ACL Prolog to go
> looking for a second value to bind to ?x, so I see it backtracing into
> gcf and then failing... why is that? gcf (now) looks like this:
>
> (<-- (gcf ?x ?y ?f)
> * *(lisp ?f (gcd ?x ?y)))
>
> That is a little more succinct than the original, with no effect on the
> issue at hand. All invocations have ?x and ?y bound and ?f unbound.
> Seems to me the next clause should always be able to bind ?f.
>
> back to the doc....
>
> kt
>
> --http://www.theoryyalgebra.com/
>
> "In the morning, hear the Way;
> * in the evening, die content!"
> * * * * * * * * * * *-- Confucius- Hide quoted text -
>
> - Show quoted text -


I would say you have a bug in ACL Prolog. Btw what is the role of
Prolog in your app (just curious)?

Mark
Reply With Quote
  #8  
Old 01-16-2008, 03:28 PM
Alessio
Guest
 
Default Re: Nooby stumped by effect of repeated rule

on swi-prolog:

1 ?- X = Y, X = Y.

X = Y

could it be that the first and second ?y somehow refer to different
variables? (this would be a bug IMHO). What happens if instead of ?y
you use an anonymous variable? (that would be _ in Prolog I think,
don't know in your implementation...)

AS
Reply With Quote
  #9  
Old 01-16-2008, 03:49 PM
Ken Tilton
Guest
 
Default Re: Nooby stumped by effect of repeated rule



Paul Tarvydas wrote:
> I've got a debugged version of PAIP (if you want it, ask me ; also, I have
> an alpha version of a WAM written in CL patterned closely on Hassan
> Ait-Kaci's tutorial, if someone wants to continue debugging it...).
>
> To (begin to) answer your question, here is what my PAIP compiles your
> top-level queries to:
>
>
> This:
> (?- (gcf 15 12 ?x) (= ?x ?y) (>> ?y 1))
>
> compiles to:
>
> (DEFUN TOP-LEVEL-QUERY/0 (CONT)
> (LET ((?X (?)))
> (GCF/3 '15
> '12
> ?X
> #'(LAMBDA ()
> (>>/2 ?X '1 #'(LAMBDA () (SHOW-PROLOG-VARS/2 '("?X" "?Y")
> (LIST ?X ?X) CONT)))))))
>
>
> While this:
>
> (?- (gcf 15 12 ?x) (= ?x ?y) (>> ?y 1) (= ?x ?y))
>
> compiles to:
>
> (DEFUN TOP-LEVEL-QUERY/0 (CONT)
> (LET ((?X (?))) (GCF/3 '15 '12 ?X #'(LAMBDA () (>>/2 ?X '1 #'(LAMBDA ()
> NIL))))))
>
> I.E. the PAIP compiler 'optimizes' the second query to fail.
>
> Likewise:
> (?- (= ?x ?y) (= ?x ?y))
>
> compiles to:
> (DEFUN TOP-LEVEL-QUERY/0 (CONT) NIL)
>
> Why? I don't know, yet...
>


Ah, thx, could be relevant since ACL Prolog began from Norvig's.

Well, luckily that was a mistake having the same clause in twice, I'll
get on with my life (which might eventually lead to borrowing your alpha
WAM).

kt


--
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
in the evening, die content!"
-- Confucius
Reply With Quote
  #10  
Old 01-16-2008, 04:31 PM
Ken Tilton
Guest
 
Default Re: Nooby stumped by effect of repeated rule



Mark Tarver wrote:
> On 16 Jan, 19:50, Ken Tilton <kennytil...@optonline.net> wrote:
>
>>Mark Tarver wrote:
>>
>>>On 16 Jan, 17:39, Ken Tilton <kennytil...@optonline.net> wrote:

>>
>>>>Total noob, here, using a Lisp implementation of Prolog (AllegroCL's, to
>>>>be precise) in case anything looks odd.

>>
>>>>Given:

>>
>>>>(<-- (gcf ?x ?y ?f)
>>>> (is ?f (gcd ?x ?y))) ;; is/2 let's me use Lisp in the second arg

>>
>>>>(<-- (> ?x ?y)
>>>> (lispp (> ?x ?y))) ;; some more embedded Lisp

>>
>>>>Applying the above, we test a hardcoded pair (12 1nd 15) to see if they
>>>>have gcf > 1:

>>
>>>>(?- (gcf 15 12 ?x)
>>>> (= ?x ?y)
>>>> (> ?y 1))

>>
>>>>?X = 3
>>>>?Y = 3

>>
>>>>No.

>>
>>>>Fine. But now:

>>
>>>>(?- (gcf 15 12 ?x)
>>>> (= ?x ?y)
>>>> (> ?y 1)
>>>> (= ?x ?y))

>>
>>>>No.

>>
>>>>The duplication of the line (in the real world case from which this was
>>>>distilled) was inadvertent and has been corrected, but I am still
>>>>curious as to why it causes the rule to fail. Is this proper Prolog, or
>>>>should I make a bug report to the vendor?

>>
>>>>kt

>>
>>>>ps. duh, it just occurred to me to grab a prolog somewhere and try
>>>>something similar in pure prolog. will do. kt

>>
>>>>--http://www.theoryyalgebra.com/

>>
>>>>"In the morning, hear the Way;
>>>> in the evening, die content!"
>>>> -- Confucius

>>
>>>This is what I get under Qi Prolog.

>>
>>>Qi 2007, Copyright (C) 2001-2007 Mark Tarver
>>>www.lambdassociates.org
>>>version 9.0 (Turbo-E)

>>
>>>(0-) (defprolog

>>
>>> "gcf(X,Y,F) :- is(F, (gcd X Y)).
>>> gter(X, Y) :- when((> X Y)).

>>
>>> kenny(X) :- gcf(15,12,X), =(X,Y), gter(Y,1), =(X,Y).")
>>>[gcf* gter* kenny*]

>>
>>>(1-) (define gcd
>>> X Y -> (GCD X Y))
>>>======> Warning:
>>>the following variables are free in gcd: GCD;
>>>gcd

>>
>>>(2-) (ask [kenny X])

>>
>>>X = 3

>>
>>>More? (y/n) y

>>
>>>run time 0 seconds
>>>5 logical inferences
>>>infinite LIPS
>>>false

>>
>>Thanks. A little leashing indicates the second occurrence of (= ?x ?y)
>>causes (as best my poor understanding of Prolog allows) ACL Prolog to go
>>looking for a second value to bind to ?x, so I see it backtracing into
>>gcf and then failing... why is that? gcf (now) looks like this:
>>
>>(<-- (gcf ?x ?y ?f)
>> (lisp ?f (gcd ?x ?y)))
>>
>>That is a little more succinct than the original, with no effect on the
>>issue at hand. All invocations have ?x and ?y bound and ?f unbound.
>>Seems to me the next clause should always be able to bind ?f.
>>
>>back to the doc....
>>
>>kt
>>
>>--http://www.theoryyalgebra.com/
>>
>>"In the morning, hear the Way;
>> in the evening, die content!"
>> -- Confucius- Hide quoted text -
>>
>>- Show quoted text -

>
>
> I would say you have a bug in ACL Prolog. Btw what is the role of
> Prolog in your app (just curious)?


Suppose you want to help a student with a problem by solving for them
one that has all the salient characteristics of their problem. The
functional requirement is "make a new problem just like this problem
only different". If we randomly choose new numbers, we will likely not
get a similar problem. Consider:

5/12 * 18/5

Now, having solved that problem thus:

5*6*3 / 6*2*5 ; merge and factor out gcf

3/2 ; cancel like factors

....and having all the details of the solution available (transformations
and results and operands of each) we can try building a new problem that
is the same. My current approach is to define methods dispatched on each
transformation ID, eg (eql 'mrg-n-factor), and have anyone who cares
offer constraints, such as any original numerator/denominator pair being
co-prime (or they could just simplify that before multiplying, which
would be a fine problem but a different kind of problem, which would be
not fine).

Long experience tells me this is a devilish problem to get right, and
the downside is truly horrific random problems. I may yet have to role
my own unifier, but with Prolog just sitting there...

kt

--
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
in the evening, die content!"
-- Confucius
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:02 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.