Type this in Prolog:
?- write(hello).
?- write(hello)
?- write(Hello).
?- write(hello world).
?- write('Hello').
?- write("hello world"). ?- halt.
cp ~gpruesse/public_html/teaching/162/labs/prologfamily/family.pl .The data is for whale families; we will assume that all whales can be categorized as male or female. You will be able to load the file's facts and predicates into Prolog by typing the name of the file (minus the .pl extension) in square brackets on the Prolog query line, as follows:
?- [family].
You are to write the following predicates (structures) into your family.pl file. Add the new structures to the end of the file. At the end of the file as it is given to you is an example structure, coparents, which you can use as a model for your own structures.
brother(X,B)
/* Can be used to answer the following questions: * if YOU instantiate X, and let Prolog instantiate B, * then you can find the first (second, third...) brother of your X. * If you instantiate B, and let Prolog instantiate X, * then you can find all those entities who have B as a brother. * If you don't instantiate either X or B, * then you can find out (one or more) pairs of entities where * the second is a brother of the first. */
cousin(X,C). % Neither self nor sibling is a cousin.You can use the operator `not(P)', which will be satisified only if P is not, or the test X==Y (for equality) or X\==Y (for not equal).
male(X):- not female(X). or male(X):- not(female(X)).
ancestor(X,Y). /* An ancestor of X is Y. * I am my own ancestor, and every ancestor of my parent is * also my ancestor; nobody else is my ancestor. */For ancestor, you will need multiple clauses -- they are "OR"ed together, or you can regard them as "If" conditions. For example, one way to write a recursive fibonacci calculator is the following:
fib(1,1). fib(2,1). %the second fibonacci number is 1. fib(N,Fn):- N1 is N-1, fib(N1,Fn1), N2 is N1-1, fib(N2,Fn2), Fn = Fn1+Fn2.
fname(X,Y) % X and Y have the same family name.
[Hint: you may want to define predicateshasmother(X), nomother(X), topmother(X,G).]