Prolog is a theorem proving system using first order predicate logic - a term you can ignore for now. It is better to start by thinking of Prolog as a logical inference system which uses facts and rules to determine if something of interest can be inferred from that information. Facts are expressed as
father(bill, ted).
Note the lower case. Here father is a predicate, and bill, ted are atoms. It is useful to think of atoms as constants. Whether bill is ted's father or vice versa is a matter of interpretation. You will need to enforce the idea that e.g., bill is ted's father by consistent use and interpretation. Inconsistent use is a serious source of bugs. Another fact might be
mother(sandra,ted).
This leads to the idea of the following rule: Someone is ted's parent if they are either his father or mother, expressed like this:
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
Note the upper case which is used for variables. Prolog uses the term goal for something that is to be satisfied. Satisfaction means Prolog can find sufficient facts to ultimately determine values (called bindings) for your variables
Similarly,
grandparent(X,Y) :- parent(X,Z), parent(Z,Y).
comma (",") here indicates sequential goal satisfaction with previous variable bindings ("instantiations" in Prolog-speak) carried forward (think about it).
E.g., if I ask Prolog to satisfy the goal
?- father(X, ted).
It will come back and print
X = bill
meaning it has found a solution (proved a theorem) that there is a father for ted that can be inferred from the facts and rules you have stated.
This works the other way also such that the goal
?- father(bill, X).
It will come back and print
X = ted
meaning it has found a solution that bill is someones father.
If you ask Prolog
?- father(X, joe).
It will come back and say
False
meaning no solution exists from your provided facts and rules.
Finally if you ask Prolog
?- father(F, S).
It will come back and print
F = bill, S = ted
If you ask Prolog
?- parent(P, C).
It will come back and print
P = bill, C = ted
as the first solution since that is the order of the facts you gave that support a conclusion to this theorem. There are higher level you can write that will find all possible solution. many if these built-in to Prolog so you almost would never have to actually do that.
If you require Prolog to find a second conclusion (satisfaction) it will It will come back and print
P = sandra, C = ted
Realistic programs will lead to a series of goal satisfactions in the prescribed manner carring their variable bindings forward to subsequent goals, which is where backtracking (built-in to the mechanics of Prolog) comes in. After some goals have been satisfied, a subsequent one may fail, then Prolog will automatically backtrack and find an alternate solution (variable bindings) to some antecedent goal as far back as necessary to find a solution. If it exhausts all backtracking possibilities it will declare a grand failure meaning to you have no solution.
Thus to craft a Prolog program is to state all the facts of the case, plus whatever rules represent domain knowledge of your problem then ask Prolog to satisfy some top level goal that will provoke Prolog to find a solution.
Finally, Prolog is a serious system. I once reduced a 10K line C++ simulation which was never correct to 1500 lines of Prolog.