家系図
とりあえず、prologでは家系図を作ってみるのが定石らしい。
ので、華麗なる一族 (競馬) - Wikipediaことマイリー系を作ってみる。
あまり大きいのは辛いので、ここで断念。
/* -*- mode: prolog -*- * horse-family.pl */ /* 牝馬 */ female(mairie). % マイリー female(cupit). % キユーピット female(yamapit). % ヤマピット female(misumaruichi). % ミスマルイチ female(itto). % イットー female(hagino_top_lady). % ハギノトップレディ female(daiichi_ruby). % ダイイチルビー female(daiichi_ciger). % ダイイチシガー /* 牡馬 */ male(nearula). % ニアルーラ male(solonaway). % ソロナウェー male(never_beat). % ネバービート male(venture). % ヴェンチア male(sancy). % サンシー male(tesco_boy). % テスコボーイ male(tousyou_body). % トウショウボーイ male(tony_bin). % トニービン male(hagino_kamui_oh). % ハギノカムイオー /* 母 */ mother_of(mairie, cupit). mother_of(cupit, yamapit). mother_of(cupit, misumaruichi). mother_of(misumaruichi, itto). mother_of(itto, hagino_top_lady). mother_of(itto, hagino_kamui_oh). mother_of(hagino_top_lady, daiichi_ruby). mother_of(daiichi_ruby, daiichi_ciger). /* 父 */ father_of(nearula, cupit). father_of(solonaway, yamapit). father_of(never_beat, misumaruichi). father_of(venture, itto). father_of(sancy, hagino_top_lady). father_of(tesco_boy, hagino_kamui_oh). father_of(tony_bin, daiichi_ciger). father_of(tousyou_body, daiichi_ruby). father_of(tony_bin, daiichi_ciger).
これを元に規則を加えていく。
両親。ORは並べて書く。
parents_of(P, C) :- father_of(P, C). parents_of(P, C) :- mother_of(P, C).
息子。ANDはカンマでつなげて書く。
son_of(S, P) :- parents_of(P, S), male(S). daughter_of(D, P) :- parents_of(P, D), female(D). grandmother(GM, C) :- mother_of(GM, P), parents_of(P, C).
ORは並べて、ANDはつなげて、だけ覚えておけば、家系図の定義はできる。