Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
:- use_module(library(clpfd)). transition(even, term, X, _) :- X #= 0. transition(even, odd, X, Y) :- X #\= 0, Y #= X - 1. transition(odd, term, X, _) :- X #= 0. transition(odd, even, X, Y) :- X #\= 0, Y #= X - 1. transition(fac, term, X, _) :- X #= 0. transition(fac, fac, X, Y) :- X #\= 0, Y #= X - 1. transition(f, f, X, Y) :- Y #= X-1. hasBaseCase(X) :- transition(X,Y,_,_), X\=Y. noBaseCase(X) :- \+ (hasBaseCase(X)). infCountdown(X, Y) :- transition(X, term, C1, _), transition(X, X, Z, 0), Z #> C1, Y #< C1, \+ (transition(X, term, Y, _)). infCountdown(X, Y) :- transition(X, term, C1, _), transition(X, X, Z, 0), Z #< C1, Y #> C1, \+ (transition(X, term, Y, _)). nStepTransition(1, X, Y, Z, W) :- transition(X, Y, Z, W). nStepTransition(N, X, Y, Z, W) :- N \= 1, M is N-1, nStepTransition(M, X, A, Z, B), transition(A, Y, B, W). infCountdown2(X, Y) :- transition(X, term, C1, _), nStepTransition(2, X, X, Z, 0), Z #> C1, Y #< C1, \+ (transition(X, term, Y, _)), \+ nStepTransition(2, X, term, Y, 0). % ?- noBaseCase(f). % true % ?- infCountdown(fac, X). % X in inf .. -1 % ?- infCountdown2(even, X). % X in inf .. -1