<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Samet Kilictas&#039;s Blog &#187; Prolog</title>
	<atom:link href="http://samet.kilictas.com/tag/prolog/feed/" rel="self" type="application/rss+xml" />
	<link>http://samet.kilictas.com</link>
	<description>J2E, PHP, Linux, PL/SQL and other random rants</description>
	<lastBuildDate>Sun, 06 Nov 2011 04:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Example Code #4 &#8211; Intersect and Write in Prolog</title>
		<link>http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/</link>
		<comments>http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 12:13:38 +0000</pubDate>
		<dc:creator>Samet Kilictas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Prolog]]></category>
		<category><![CDATA[append]]></category>
		<category><![CDATA[intersect]]></category>
		<category><![CDATA[member]]></category>

		<guid isPermaLink="false">http://samet.kilictas.com/?p=221</guid>
		<description><![CDATA[1- &#8220;!&#8221; character stops the query when it is false and &#8220;;&#8221; runs as &#8220;or&#8221; so it skips the false part then moves next part smaller(X,Y):- X X&#62;Y,write(Y),write(' is bigger then '),write(X),!; write('They are equal'). Query -&#62; ?smaller(3,5) : 3 is smaller then 5 Query -&#62; ?smaller(8,5) : 8 is bigger then 5 Query -&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1- &#8220;!&#8221; character stops the query when it is false and &#8220;;&#8221; runs as &#8220;or&#8221; so it skips the false part then moves next part</strong></p>
<p><code>smaller(X,Y):- X<br />
X&gt;Y,write(Y),write(' is bigger then '),write(X),!;<br />
write('They are equal').</code></p>
<p>Query -&gt; <code>?smaller(3,5)  : 3 is smaller then 5</code><br />
Query -&gt; <code>?smaller(8,5)  : 8 is bigger then 5</code><br />
Query -&gt; <code>?smaller(5,5)  : They are equal</code></p>
<p><strong>2- Intersect relation</strong></p>
<p>Intersect function uses an external function inside. Member function checks whether the first parameter is member of the given list or not.</p>
<p>Query -&gt; <code>member(3,[3,4,5]).</code></p>
<p><code>member(HM,[HM|TM]).<br />
member(XM,[HM|TM]):- member(XM,TM).</code></p>
<p>and the intersect function gives you the result on LI variable. Try it.</p>
<p>intersect([ ],LI,[ ]).<br />
intersect([HI|TI],LI,LI2):- member(HI,LI),intersect(TI,LI,LI3),LI2=[HI|LI3],!;intersect(TI,LI,LI2).</p>
<p>Query -&gt; <code>intersect([3,4],LI,[4,5]) : [4]</code></p>
<a href='http://twitter.com/share?url=http%3A%2F%2Fsamet.kilictas.com%2F%3Fp%3D221&count=vertical&related=&text=Example%20Code%20%234%20-%20Intersect%20and%20Write%20in%20Prolog' class='twitter-share-button' data-text='Example Code #4 - Intersect and Write in Prolog' data-url='http://samet.kilictas.com/?p=221' data-counturl='http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/' data-count='vertical' data-via='sametkilictas'>Tweet</a>]]></content:encoded>
			<wfw:commentRss>http://samet.kilictas.com/example-code-4-intersect-and-write-in-prolog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Example Code #3 &#8211; Basics in Prolog</title>
		<link>http://samet.kilictas.com/example-code-3-basics-in-prolog/</link>
		<comments>http://samet.kilictas.com/example-code-3-basics-in-prolog/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 13:16:35 +0000</pubDate>
		<dc:creator>Samet Kilictas</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Prolog]]></category>
		<category><![CDATA[factorial]]></category>
		<category><![CDATA[fibonacci]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[Sister]]></category>
		<category><![CDATA[swi prolog]]></category>

		<guid isPermaLink="false">http://samet.kilictas.com/?p=207</guid>
		<description><![CDATA[1- Parent relation between rex, doggie and goldie dog(rex). dog(X):-parent(X,Y). parent(goldie,rex). parent(jack,rex). Query -> ?dog(goldie) : YES Query -> ?dog(jack) : YES 2- Sister relation sister(X,Y):-girl(X),girl(Y),parent(X,Z),parent(Y,Z). parent(sara,Maria). parent(lili,Maria). girl(lili). girl(maria). Query -> ?sister(lili,maria) : NO 3- Finds factorial of numbers 1!: 1 , 2!: 2&#215;1, 3!: 3x2x1 Here you can see that we are able [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1- Parent relation between rex, doggie and goldie</strong></p>
<p><code>dog(rex).<br />
dog(X):-parent(X,Y).<br />
parent(goldie,rex).<br />
parent(jack,rex).</code></p>
<p>Query -> <code>?dog(goldie)  : YES</code><br />
Query -> <code>?dog(jack)  : YES</code></p>
<p><strong>2- Sister relation</strong></p>
<p><code>sister(X,Y):-girl(X),girl(Y),parent(X,Z),parent(Y,Z).<br />
parent(sara,Maria).<br />
parent(lili,Maria).<br />
girl(lili).<br />
girl(maria).</code></p>
<p>Query -> <code>?sister(lili,maria) : NO</code></p>
<p><strong>3- Finds factorial of numbers</strong></p>
<p>1!: 1 , 2!: 2&#215;1, 3!: 3x2x1<br />
Here you can see that we are able to say 3!: 3&#215;2!  instead of 3!:3x2x1 . Since i know what is 1! and 0! therefore i have limitation points for my program.</p>
<p><code>fact(0,1):-!.<br />
fact(1,1):-!.<br />
fact(N,F,F1) :- N1 is N-1, fact(N1,F1), F is N * F1.</code></p>
<p><span id="more-207"></span></p>
<p><strong>4- Finds Fibonacci numbers</strong></p>
<p>1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,&#8230; </p>
<p><code>fib(0,0):-!.<br />
fib(1,1):-!.<br />
fib(X,L) :- X > 1, 	Y1 is X-1, Y2 is X-2, fib(Y1,F1), fib(Y2,F2), L is F1+F2.</code></p>
<a href='http://twitter.com/share?url=http%3A%2F%2Fsamet.kilictas.com%2F%3Fp%3D207&count=vertical&related=&text=Example%20Code%20%233%20-%20Basics%20in%20Prolog' class='twitter-share-button' data-text='Example Code #3 - Basics in Prolog' data-url='http://samet.kilictas.com/?p=207' data-counturl='http://samet.kilictas.com/example-code-3-basics-in-prolog/' data-count='vertical' data-via='sametkilictas'>Tweet</a>]]></content:encoded>
			<wfw:commentRss>http://samet.kilictas.com/example-code-3-basics-in-prolog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

