Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

foo(0,Y,Z) :- Z is Y.
foo(X,0,Z) :- Z is X.
foo(X,Y,Z) :- X>=Y, M1 is X-2, foo(M1, Y, Zx), Z is Zx + Y.
foo(X,Y,Z) :- Y<X, N1 is Y-3, foo(X, N1, Zx), Z is Zx + X.

So this is my program and this is what i'm trying to accomplish

??????(??, ??) = {

?? ???? ?? ≤ 0

?? ???? ?? ≤ 0

?? + ??????(?? ? 2, ??) ???? ?? ≥ ??

?? + ??????(??, ?? ? 3) ???? ?? < ?? }

Why does my program not output anything? This is what i think i'm saying -

If X = 0, foo(0,Y,Z), than return Z as Y. If Y = 0, foo(0,Y,Z), than return Z as X.

if X>=Y, than do foo again and once that returns than return Z as Zx + Y if X

Am i correct in my thinking?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
167 views
Welcome To Ask or Share your Answers For Others

1 Answer

I remember that in your function is

?? ???? ?? ≤ 0
?? ???? ?? ≤ 0

that is "less or equal to zero" not "equal to zero".

So I suppose that

foo(0,Y,Z) :- Z is Y.

should be

foo(X, Y, Y) :- X =< 0.

and that

foo(X,0,Z) :- Z is X.

should be

foo(X, Y, X) :- Y =< 0.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...