/* Nilsson's Elephants in Picat. https://github.com/ikokkari/AI/blob/master/CCPS%20721%20Artificial%20Intelligence%20Extras.pdf """ Sam, Clyde and Oscar are elephants. Sam is pink. Clyde is gray. Clyde likes Oscar, and Oscar likes Sam. Prove that some gray elephant likes some pink elephant. """ The assumption is that there are either pink or gray elephants, so Oscar must be either pink or gray, but we don't know which. * If Oscar is pink: [gray = clyde,likes,pink = oscar] The gray elephant Clyde likes the pink elephant Oscar * If Oscar is gray: [gray = oscar,likes,pink = sam] The gray elephant Oscar likes the pink elephant Sam This is very similar to the problem in married_looking_at_unmarried.pi (which also include some different approaches). In go2/0 is a solution using a DCG. This problem is from Nils J. Nilsson: "Artificial Intelligence: A New Synthesis", 1998 """ 16.7 Sam, Clyde, and Oscar are elephants. We know the following facts about them: 1. Sam is pink. 2. Clyde is gray and likes Oscar. 3. Oscar is either pink or gray (but not both) and likes Sam. Use resolution refutation to prove that a gray elephant likes a pink elephant; that is, prove (Ex,y)[Gray(x) /\ Pink(y) /\ Likes(x,y)] """ Note that Nilsson clearly states that Oscar is either piml or gray (but not both). This is missing from ikokkari's problem statement (and is what might the problem a little tricky). This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. /* [gray = clyde,likes,pink = oscar] [gray = oscar,likes,pink = sam] */ go ?=> likes(E1,E2), color(E1,gray), color(E2,pink), println([gray=E1,likes,pink=E2]), fail, nl. go => true. % % Using DCGs: % % The gray elephant clyde likes the pink elephant oscar. % The gray elephant oscar likes the pink elephant sam. % go2 ?=> likes2(X,[]), println(X), fail, nl. go2 => true. % % Using cl_facts % [gray,clyde,likes,pink,oscar] % [gray,oscar,likes,pink,sam] % go3 ?=> cl_facts($[likes3(clyde,oscar),likes3(oscar,sam), color3(sam,pink),color3(clyde,gray), color3(oscar,gray),color3(oscar,pink)]), likes3(E1,E2), color3(E1,gray), color3(E2,pink), println([gray,E1,likes,pink,E2]), fail, nl. go3 => true. % % Who likes whom. % likes(clyde,oscar). likes(oscar,sam). % % An elephant is either pink or gray. % color(sam,pink) => true. color(clyde,gray) => true. color(_Elephant,Color) => Color = pink ; Color = gray. % % DCG approach. % likes2 --> "The gray elephant ", gray(Gray), " ", "likes", " ", "the pink elephant ", pink(Pink), ".", {likes(Gray,Pink)}. % Oscar is either gray or pink. gray(clyde) --> "clyde". gray(oscar) --> "oscar". pink(sam) --> "sam". pink(oscar) --> "oscar".