New to logic programming (Prolog). Come across a simple question but dont know how to code it in prolog.
Question is like you have several arguements: argument(a),argument(b)..., and several attack relations like attack(a,b) which means argument a attacks argument b. So given an argument I want to find out if it is a grounded one. "Grounded" for an argument a means if b attacks a, then there exists another argument, say c attacks b. If no argument attacks c then we say a and c are grounded.
Can you give an example how to implement this grounded/1 program to achieve this goal.
Not sure I make it clear....But welcome to give any advice (or code)!!
What I've understand from your explanation, an argument is grounded when there are no other grounded arguments attacking it.
You can define a procedure grounded/1
which obeys this rule straightforward in prolog:
grounded(A):-
argument(A), % A is an argument
\+ % for which there does not exist
(
attack(B, A), % an attacker
grounded(B) % which is grounded
).
[Edit after comment by OP]: If you have to deal with cycles, then you will probably need to keep a list of visited "attacks", no forbid cycles:
grounded(A):-
grounded(A, []).
grounded(A, L):-
argument(A),
\+
(
attack(B, A),
\+ member(B, L), % Here we forbid cycles
grounded(B, [A|L]) % We add the current argument to the list of forbidden arguments
).