We have just started to learn prolog in my classroom and our first exercise goes as follows:
Problem:
Note: assume that there are only two atoms such as a and b instead of infinitely many.
a) Write a prolog program that translates the inductive definition of Propositional Logic formula (i.e. that translates Definition 1). For this, you need to use:
1.) a unary predicate “at” to denote atomic formulas (so “at(f)” means “F is an atomic formula”, where f is a constant).
2.) a unary predicate “fmla” to denote formulas (so “fmla(F)” means “F is a formula”).
3.) a unary operation “neg” to denote negation (so “neg(F)” stands for ¬F).
4.) a binary operation “or” to denote disjunction of two formulas (so “or(F,G)” stands for (F∨G)).
Attempt:
at(a). % Our first atom.
at(b). % Our second atom.
fmla(F):-
at(F).
neg(F):-
fmla(F).
or(F,G):-
fmla(F), fmla(G).
fmla(F):-
or(F,G),
neg(F),
fmla(G).
Example of a valid formula: (~A v B) ---> or(neg(a), b).
I believe that the way that I've struct my program is correct but the recursive part doesn't work(I'm also getting a singleton error there). I've trying to figure this out for hours but to no avail. Any help would be appreciated.