Advertisement
yegoblynqueenne

Learning Peano successor/ predeessor functions.

Nov 10th, 2020
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.26 KB | None | 0 0
  1. :-module(pred_succ, [background_knowledge/2
  2.                     ,metarules/2
  3.                     ,positive_example/2
  4.                     ,negative_example/2
  5.                     ]).
  6.  
  7. /** <module> Learning Peano successor and predecessor functions.
  8.  
  9. Learning queries:
  10.  
  11. ==
  12. ?- learn(s/2).
  13. s(0,s(A)).
  14. s(A,B):-s_(A,B).
  15. s(A,B):-s_(A,C),s(C,B).
  16. true.
  17.  
  18. ?- learn(p/2).
  19. p(s(A),0).
  20. p(A,B):-p_(A,B).
  21. p(A,B):-p_(A,C),p(C,B).
  22. true.
  23. ==
  24.  
  25. */
  26.  
  27. % Eliminates left-recursive clauses that make it harder for Prolog to
  28. % run the learned hypothesis.
  29. configuration:metarule_constraints(M,fail):-
  30.     M =.. [m,Id,P|Ps]
  31.     ,Id \= projection
  32.     ,left_recursive(P,Ps).
  33.  
  34. left_recursive(T,[T|_Ps]):-
  35.     !.
  36. left_recursive(T,[T,T|_Ps]):-
  37.     !.
  38.  
  39.  
  40. metarules(s/2, [identity,chain]).
  41. metarules(p/2, [identity,chain]).
  42.  
  43. background_knowledge(s/2, [s_/2]).
  44. background_knowledge(p/2, [p_/2]).
  45.  
  46. positive_example(s/2, E):-
  47.         member(E,[s(0,s(_))
  48.                  ,s(0,s(0))
  49.                  ,s(s(0),s(s(s(s(0)))))
  50.                ]).
  51. positive_example(p/2, E):-
  52.         member(E,[p(s(_),0)
  53.                  ,p(s(0),0)
  54.                  ,p(s(s(s(s(0)))),s(0))
  55.                ]).
  56.  
  57. negative_example(s/2, _):-
  58.     fail.
  59. negative_example(p/2, _):-
  60.         fail.
  61.  
  62. s_(N,s(N)).
  63.  
  64. p_(s(N),N).
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement