Prolog - deconstructing goals into individual facts and arithmetic -
i'm attempting write small program breaks given goal smallest parts , evaluates them. far have:
alien(x) :- frommars(x), fromsaturn(x); fromjupiter(x), x = 'john'. frommars(john). fromsaturn(john). fromjupiter(john). test(true) :- !. test((goal1,goal2)) :- test(goal1), test(goal2). test((goal1;goal2)) :- test(goal1), test(goal2). test(x = y) :- call(x = y). test(goal) :- clause(goal,body),test(body).
as far can tell far, recursively inspect rules using clause/2 e.g. if call test(alien(john)).
. when reaches point body
contains facts such frommars(x), fromsaturn(x); fromjupiter(x), x = 'john'
split using test((goal1,goal2)) :-
, test((goal1;goal2)) :-
rules, reaching singular facts. when passed singular fact, clause/2 instantiate body
true if can solved.
problems arise arithmetic. in above program, there singular goal x = 'john'
causes error clause/2 (private procedure?). introduced rule test(x = y) :-
catch case can deal way. want rule catch arithmetic. cant write rule in style of test(x = y) :-
catch possible types of arithmetic.
my goal write abductive meta-interpeter can handle type of rule thrown @ it.
let me know if none of makes sense , i'll try clarify :)
meta interpreters it's 1 of 'strong points' of prolog. see this page markus triska interesting theme.
as little booby tables advised, can capture arithmetic simple as
test(x y) :- x y.
btw think have typo here
test((goal1;goal2)) :- test(goal1), test(goal2).
should be
test((goal1;goal2)) :- test(goal1) ; test(goal2).
edit: working operators can generalized, if required. example of builtins required:
?- x = (1+2), x =.. [f, a, b], current_op(u, v, f). x = 1+2, f = (+), = 1, b = 2, u = 200, v = fy .
Comments
Post a Comment