# prolog rule problem

Page 1 of 1

## 3 Replies - 843 Views - Last Post: 07 October 2012 - 06:03 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294255&amp;s=79f18c2fa9c91e71aeb2713d7474d64b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Ap0C552

• D.I.C Regular

Reputation: -6
• Posts: 321
• Joined: 08-December 10

# prolog rule problem

Posted 04 October 2012 - 09:30 AM

I am creating rules that establish family relationships.

I have the rule...

```brother(X,Y):-(parent(Z,X),parent(Z,Y)),X\==Y,male(X).
```

But the problem is that it returns duplicates.

So if john has a brother joe, it will say john has two brothers named joe.

because it checks that they share a father and returns joe, and checks that they have the same mother and returns joe.

But of course I want it to work if they only have one parent in common as well.

Can anyone suggest me in the right direction?

Thanks.

Is This A Good Question/Topic? 0

## Replies To: prolog rule problem

### #2 #define

• Duke of Err

Reputation: 1602
• Posts: 5,573
• Joined: 19-February 09

## Re: prolog rule problem

Posted 05 October 2012 - 09:03 PM

You can use a cut ! to say that the current choice is the correct one, and to disallow backtracking.

```	brother(X,Y):- parent(Z,X), parent(Z,Y),
X\==Y, male(X) , !.

```

### #3 sepp2k

• D.I.C Lover

Reputation: 2270
• Posts: 3,483
• Joined: 21-June 11

## Re: prolog rule problem

Posted 06 October 2012 - 02:24 AM

#define, on 06 October 2012 - 06:03 AM, said:

You can use a cut ! to say that the current choice is the correct one, and to disallow backtracking.

But that will only return one brother even if there really are multiple brothers.

### #4 #define

• Duke of Err

Reputation: 1602
• Posts: 5,573
• Joined: 19-February 09

## Re: prolog rule problem

Posted 07 October 2012 - 06:03 PM

Thanks sepp2k that's right.

Another predicate may help something like :

```parents(M, F, C) :-

```

that defines both parents of the child.