SHARE
TWEET

Untitled

a guest Jan 21st, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. nat(c).
  2. nat(s(X)):-nat(X).
  3. sum(X,c,X).
  4. sum(X,s(Y),s(Z)):-sum(X,Y,Z).
  5. interpret(0,c).
  6. interpret(N,s(X)):-interpret(M,X),N is M+1.
  7. gen(0,c).
  8. gen(N,s(X)):-N>0,M is N-1,gen(M,X).
  9. bezout(X,0,X,1,0).
  10. bezout(X,Y,D,U,V):-X>=Y,Y>0,X1 is X-Y,bezout(X1,Y,D,U,V1),V is V1-U.
  11. bezout(X,Y,D,U,V):-X<Y,bezout(Y,X,D,V,U).
  12. fib(X,X):-X=<1.
  13. fib(N,F):-N>=2,fib(N-1,F1),fib(N-2,F2),F is F1+F2.
  14. fib2(0,0,1).
  15. fib2(N,F1,F2):-N>0,N1 is N-1,fib2(N1,F3,F1),F2 is F1+F3.
  16. mem(X,[X|_]).
  17. mem(X,[_|L]):-mem(X,L).
  18. reverse([],L1,L1).
  19. reverse([X|L2],L1,R):-reverse(L2,[X|L1],R).
  20. rev(L,R):-reverse(L,[],R).
  21. cat([],Y,Y).
  22. cat([A|L],Y,[A|Z]):-cat(L,Y,Z).
  23. mem2(X,L):-cat(_,[X|_],L).
  24. perm([],[]).
  25. perm([A|L1],P):-perm(L1,P1),cat(P2,P3,P1),cat(P2,[A|P3],P).
  26. ordered([]).
  27. ordered([_]).
  28. ordered([A,B|L]):-A=<B,ordered([B|L]).
  29. sort2(L,S):-permutation(L,S),ordered(S).
  30. unordered(S):-cat(_,[A,B|_],S),A>B.
  31. sort3(L,S):-perm(L,S),not(unordered(S)).
  32. edge(E,U,V):-mem([U,V],E).
  33. edge(E,U,V):-mem([V,U],E).
  34. nonhamiltonian(E,H):-cat(_,[U,V|_],H),not(edge(E,U,V)).
  35. hamiltonian(V,E,H):-perm(V,H),not(nonhamiltonian(E,H)).
  36. subword(L,W):-cat(_,V,L),cat(W,_,V).
  37. subsequence([],[]).
  38. subsequence([A|L],[A|S]):-subsequence(L,S).
  39. subsequence([_|L],S):-subsequence(L,S).
  40. subset(V,_,V1):-subsequence(V,V1).
  41. is_not_clique(E,V1):-mem(U,V1),mem(W,V1),U\=W,not(edge(E,U,W)).
  42. is_clique(E,V1):-not(is_not_clique(E,V1)).
  43. clique(V,E,V1):-subset(V,E,V1),is_clique(E,V1).
  44. len([],0).
  45. len([_|L1],N):-len(L1,N1),N is N1+1.
  46. clique_size(V,E,V1,N1):-clique(V,E,V1),len(V1,N1).
  47. exists_bigger_clique(V,E,N):-clique_size(V,E,_,N1),N1>N.
  48. max_clique(V,E,V1):-clique_size(V,E,V1,N1),not(exists_bigger_clique(V,E,N1)).
  49. between2(I,J,I):-I=<J.
  50. between2(I,J,K):-I<J,I1 is I+1,between2(I1,J,K).
  51. all_functions([],_,[]).
  52. all_functions([A|V1],K,[[A,K1]|C1]):-between2(1,K,K1),all_functions(V1,K,C1).
  53. is_not_colouring(_,E,C):-mem([U,K],C),mem([W,K],C),edge(E,U,W).
  54. is_colouring(_,E,C):-not(is_not_colouring(_,E,C)).
  55. colouring(V,E,K,C):-all_functions(V,K,C),is_colouring(V,E,C).
  56. merge1(S1,[],S1).
  57. merge1([],[A|S2],[A|S2]).
  58. merge1([A|S1],[B|S2],[A|S]):-A=<B,merge1(S1,[B|S2],S).
  59. merge1([A|S1],[B|S2],[B|S]):-A>B,merge1([A|S1],S2,S).
  60. split1(L,L1,L2):-cat(L1,L2,L),len(L1,N1),len(L2,N2),N1-N2=<1,N1>=N2.
  61. split([],[],[]).
  62. split([A],[A],[]).
  63. split([A,B|L],[A|L1],[B|L2]):-split(L,L1,L2).
  64. merge_sort([],[]).
  65. merge_sort([A],[A]).
  66. merge_sort([A,B|L],S):-split([A,B|L],L1,L2),merge_sort(L1,S1),merge_sort(L2,S2),merge1(S1,S2,S).
  67. transition_det(Q,T,S,F,P,A,P1):-mem([P,A,P1],T).
  68. traverse_det(Q,T,S,F,P,[],P).
  69. traverse_det(Q,T,S,F,P,[A|W1],P1):-transition_det(Q,T,S,F,P,A,P2),traverse_det(Q,T,S,F,P2,W1,P1).
  70. recognise_det(Q,T,S,F,W):-traverse_det(Q,T,S,F,S,W,P),mem(P,F).
  71. natural(0).
  72. natural(X):-natural(Y),X is Y+1.
  73. graph_g1(M,0,Y):-M mod 2 =:=1,Y is (M-1)/2.
  74. graph_g1(M,X,Y):-M mod 2 =:=0,M1 is M/2,graph_g1(M1,X1,Y),X is X1+1.
  75. pairs(X,Y):-natural(N),M is N+1,graph_g1(M,X,Y).
  76. genA(N,X,Y):-between2(0,N,X),Y is N-X.
  77. pairs2(X,Y):-natural(N),genA(N,X,Y).
  78. genBoundedSeq(N,M,[]):-M>=0.
  79. genBoundedSeq(N,M,[A]):-M>=1,between2(0,N,A).
  80. genBoundedSeq(N,M,[A|[B|L]]):-M>=2,M1 is M-1,genBoundedSeq(N,M1,[B|L]),B1 is B-1,between2(0,B1,A).
  81. genSet(S):-pairs2(N,M),genBoundedSeq(N,M,S).
  82. genRelation([],[]).
  83. genRelation([N|M],[[X,Y]|R]):-between2(0,N,X), Y is N-X,genRelation(M,R).
  84. irreflexive(R):-mem2([X,_],R),not(mem2([X,X],R)).
  85. irreflexive(R):-mem2([_,X],R),not(mem2([X,X],R)).
  86. reflexive(R):-not(irreflexive(R)).
  87. asymmetric(R):-mem2([X,Y],R),not(mem2([Y,X],R)).
  88. symmetric(R):-not(asymmetric(R)).
  89. intransitive(R):-mem2([X,Y],R),mem2([Y,Z],R),not(mem2([X,Z],R)).
  90. transitive(R):-not(intransitive(R)).
  91. genFiniteEquivalenceRelations(R):-genSet(S),genRelation(S,R),reflexive(R),symmetric(R),transitive(R).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top