non-termination

Prolog successor notation yields incomplete result and infinite loop

一曲冷凌霜 提交于 2019-11-26 11:51:47
I start to learn Prolog and first learnt about the successor notation. And this is where I find out about writing Peano axioms in Prolog. See page 12 of the PDF : sum(0, M, M). sum(s(N), M, s(K)) :- sum(N,M,K). prod(0,M,0). prod(s(N), M, P) :- prod(N,M,K), sum(K,M,P). I put the multiplication rules into Prolog. Then I do the query: ?- prod(X,Y,s(s(s(s(s(s(0))))))). Which means finding the factor of 6 basically. Here are the results. X = s(0), Y = s(s(s(s(s(s(0)))))) ? ; X = s(s(0)), Y = s(s(s(0))) ? ; X = s(s(s(0))), Y = s(s(0)) ? ; infinite loop This result has two problems: Not all results

Prolog successor notation yields incomplete result and infinite loop

放肆的年华 提交于 2019-11-26 02:37:46
问题 I start to learn Prolog and first learnt about the successor notation. And this is where I find out about writing Peano axioms in Prolog. See page 12 of the PDF: sum(0, M, M). sum(s(N), M, s(K)) :- sum(N,M,K). prod(0,M,0). prod(s(N), M, P) :- prod(N,M,K), sum(K,M,P). I put the multiplication rules into Prolog. Then I do the query: ?- prod(X,Y,s(s(s(s(s(s(0))))))). Which means finding the factor of 6 basically. Here are the results. X = s(0), Y = s(s(s(s(s(s(0)))))) ? ; X = s(s(0)), Y = s(s(s