<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Discrete Math Final Project</title>
	<atom:link href="http://mathmaniacs.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mathmaniacs.wordpress.com</link>
	<description></description>
	<lastBuildDate>Tue, 22 Dec 2009 17:22:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mathmaniacs.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Discrete Math Final Project</title>
		<link>http://mathmaniacs.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mathmaniacs.wordpress.com/osd.xml" title="Discrete Math Final Project" />
	<atom:link rel='hub' href='http://mathmaniacs.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Final Project</title>
		<link>http://mathmaniacs.wordpress.com/2009/12/22/final-project/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/12/22/final-project/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 14:03:49 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Download]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/2009/12/22/final-project/</guid>
		<description><![CDATA[Greetings This is our final project about Expert Systems. You can download by click the link below. Don&#8217;t worry, it&#8217;s spam free DiscreteMath_FP_Report_ClassA_Mathmaniacs_2009 Prolog source code<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=170&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
This is our final project about Expert Systems. You can download by click the link below. Don&#8217;t worry, it&#8217;s spam free <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><a href="http://mathmaniacs.files.wordpress.com/2009/12/discretemath_fp_report_classa_mathmaniacs_2009.pdf">DiscreteMath_FP_Report_ClassA_Mathmaniacs_2009</a><a href="http://www.accio.web.id/images/events.rar"></a></p>
<p><a href="http://www.accio.web.id/images/events.rar">Prolog source code</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=170&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/12/22/final-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>
	</item>
		<item>
		<title>Prolog : Events Guide</title>
		<link>http://mathmaniacs.wordpress.com/2009/12/14/prolog-events-guide/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/12/14/prolog-events-guide/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 05:17:22 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Prolog Tutorials]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=166</guid>
		<description><![CDATA[/******************************************************* Events Guide * specialEvent(Name, Place, Month, Start-Date, * *               Finish-Date, Classification, Genre)      * *******************************************************/ specialEvent(scomdex-pameran-komputer, surabaya-expo, 11, 2, 7, family, computer). specialEvent(surabaya-sale, tunjungan-plaza, 11, 9, 21, family, shopping). specialEvent(surabaya-book-fair, surabaya-expo, 11, 16, 29, student, music). specialEvent(kids-carnaval, tugu-pahlawan, 11, 29, 29, children, art). specialEvent(music-concert, tunjungan-plaza, 12, 1, 3, adolescent, music). specialEvent(food-festival, pakuwon-city, -1, -1, -1, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=166&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>/*******************************************************<br />
Events Guide<br />
* specialEvent(Name, Place, Month, Start-Date, *<br />
*               Finish-Date, Classification, Genre)      *<br />
*******************************************************/</p>
<p>specialEvent(scomdex-pameran-komputer, surabaya-expo, 11, 2, 7, family, computer).<br />
specialEvent(surabaya-sale, tunjungan-plaza, 11, 9, 21, family, shopping).<br />
specialEvent(surabaya-book-fair, surabaya-expo, 11, 16, 29, student, music).<br />
specialEvent(kids-carnaval, tugu-pahlawan, 11, 29, 29, children, art).<br />
specialEvent(music-concert, tunjungan-plaza, 12, 1, 3, adolescent, music).<br />
specialEvent(food-festival, pakuwon-city, -1, -1, -1, family, restaurant).<br />
specialEvent(music-by-request, surabaya-radio, -1, -1, -1, adolescent, music).<br />
specialEvent(education-expo,surabaya-expo, 12, 7, 12, family ,education).<br />
specialEvent(surabaya-real-estate-expo, pakuwon-city, 12, 1, 31, adult, property).</p>
<p>foodAvailableAt(kids-carnaval, cheap).<br />
foodAvailableAt(surabaya-book-fair, medium).<br />
foodAvailableAt(surabaya-real-estate-expo, expensive).<br />
foodAvailableAt(education-expo, medium).<br />
foodAvailableAt(food-festival, cheap).<br />
foodAvailableAt(music-concert, medium).<br />
foodAvailableAt(music-by-request, medium).</p>
<p>distance(surabaya-expo, tunjungan-plaza, 5).<br />
distance(surabaya-expo, tugu-pahlawan, 7).<br />
distance(surabaya-expo, pakuwon-city, 12).<br />
distance(surabaya-expo, surabaya-radio, 8).<br />
distance(tunjungan-plaza, tugu-pahlawan, 4).<br />
distance(tunjungan-plaza, pakuwon-city, 12).<br />
distance(tunjungan-plaza, surabaya-radio, 3).<br />
distance(tugu-pahlawan,pakuwon-city,10).<br />
distance(tugu-pahlawan, surabaya-radio, 5).<br />
distance(pakuwon-city, surabaya-radio, 8).</p>
<p>/*************************************<br />
* U T I L I T Y   F U N C T I O N S *<br />
*************************************/</p>
<p>near(X,Y) :- X = Y ;  (distance(X,Y,D), D =&lt; 5) ; (distance(Y,X,D), D =&lt; 5).</p>
<p>getDates(E,M,Ds,De)  :- specialEvent(E,_,M,Ds,De,_,_).<br />
allYearEvent(E)      :- specialEvent(E,_,-1,-1,-1,_,_).<br />
suitableForKids(E)   :- specialEvent(E,_,_,_,_,family,_).</p>
<p>/*************************************<br />
* E N D U S E R   F U N C T I O N S *<br />
*************************************/</p>
<p>getEvents(E,P,C,G)    :- specialEvent(E,P,_,_,_,C,G).<br />
partyEvents(E,M,D,P) :- getEvent(E,Ep,family,G),<br />
near(P,Ep),<br />
G \= shopping,<br />
getDates(E,Em,Ds,De),<br />
(allYearEvent(E) ; (Ds =&lt; D, De &gt;= D, Em =:= M)).</p>
<p>nearEvents(E,P)      :- near(P,X), getEvent(E,X,_,_).<br />
foodAvailable(E,T)   :- foodAvailableAt(E,T) ;<br />
(getEvent(E,_,T,G), G = restaurant).</p>
<p>/*************************************<br />
* E X A M P L E   Q U E R I E S *<br />
*************************************/</p>
<p>Here are some examples of how you would use the program:</p>
<p>* Is there anything suitable for a party for someone whose birthday is on the 1st October in or near Surabay Expo.</p>
<p>? partyEvents(X,11,1,surabaya-expo).</p>
<p>* Is there food available at the music-concert, if so how expensive is it?</p>
<p>? foodAvailable(music-concert, P).</p>
<p>* List all events in or near tunjungan-plaza.</p>
<p>? nearEvents(E, tunjungan-plaza).</p>
<p>* Get all adult events in pakuwon-city</p>
<p>?getEvents(E, pakuwon-city,adult,_).</p>
<p>*/</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/166/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=166&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/12/14/prolog-events-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>
	</item>
		<item>
		<title>Loops (Exercise 3)</title>
		<link>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-3/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-3/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 06:40:16 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Prolog Tutorials]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=148</guid>
		<description><![CDATA[Greetings! Now we meet again for the exercise 3. After exercise 2, we are really sure that you guys can solve this problem easily So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy Exercise 3 Using the person [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=148&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings!</p>
<p>Now we meet again for the exercise 3. After exercise 2, we are really sure that you guys can solve this problem easily <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p>So, are we ready to rumble? <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p><strong>Exercise 3</strong></p>
<p>Using the person clauses given, find the professions of all those over 40..</p>
<p>The person clause is :</p>
<p><strong>person(john,smith,45,london,doctor).<br />
person(martin,williams,33,birmingham,teacher).<br />
person(henry,smith,26,manchester,plumber).<br />
person(jane,wilson,62,london,teacher).<br />
person(mary,smith,29,glasgow,surveyor).</strong></p>
<p>Answer :</p>
<p>To find the profession is quite easy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  just look at the source code below :</p>
<p><strong>find_prof:-person(_,_,Age,_,Prof),Age&gt;40,<br />
write(&#8216;The proffesion above age 40 is &#8216;),write(Prof),nl,fail.<br />
find_prof.<br />
person(john,smith,45,london,doctor).<br />
person(martin,williams,33,birmingham,teacher).<br />
person(henry,smith,26,manchester,plumber).<br />
person(jane,wilson,62,london,teacher).<br />
person(mary,smith,29,glasgow,surveyor).<span id="more-148"></span></strong></p>
<p>We will explain you a little bit about the source code. Just a little bit, because we know that you guys already dig it <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> . It is quite easy to find the profession with age above 40. You just simply write the rules like above. The find_prof rule means you have to find the profession from the person rules given.</p>
<p>Okhaii, let’s go to the Prolog program <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p>1. First of all, you have to write down the following program to notepad, and save as .pl file. For this exercise, we will save it as <strong>loop3.pl</strong></p>
<p><img class="alignnone size-full wp-image-150" title="loop7" src="http://mathmaniacs.files.wordpress.com/2009/12/loop7.jpg?w=495&#038;h=154" alt="" width="495" height="154" /></p>
<p>2. Open your Prolog, click File&gt;Consult and find the file you’ve just saved it. After you successfully open it, Prolog will manage to show you a successful quote just like the screenshot show.</p>
<p><img class="alignnone size-full wp-image-151" title="loop8" src="http://mathmaniacs.files.wordpress.com/2009/12/loop8.jpg?w=495&#038;h=232" alt="" width="495" height="232" /></p>
<p>3. Let’s proof the question, try the command on your Prolog :</p>
<p style="text-align:center;">find_prof.</p>
<p style="text-align:left;">After you hit enter, the result will come as shown on the screenshot.</p>
<p style="text-align:left;"><img class="alignnone size-full wp-image-152" title="loop9" src="http://mathmaniacs.files.wordpress.com/2009/12/loop9.jpg?w=495&#038;h=233" alt="" width="495" height="233" /></p>
<p>Okhaaiii then, we think it is enough for this time <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> .</p>
<p>Have you enjoy our tutorials? If there is any questions prior to the tutorials, please leave your comment right here. We will accomodate the answer as soon as possible.</p>
<p>Till we meet again with the next tutorials <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif?w=495" alt=":)" /></p>
<p>Best Regards,</p>
<p>Mathmaniacs</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=148&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop7.jpg" medium="image">
			<media:title type="html">loop7</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop8.jpg" medium="image">
			<media:title type="html">loop8</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop9.jpg" medium="image">
			<media:title type="html">loop9</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif" medium="image">
			<media:title type="html">:)</media:title>
		</media:content>
	</item>
		<item>
		<title>Loops (Exercise 2)</title>
		<link>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-2/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-2/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 05:41:33 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Prolog Tutorials]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=139</guid>
		<description><![CDATA[Greetings! Now we meet again for the exercise 2. After exercise 1, we are really sure that you guys can solve this problem easily So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy Exercise 2 Define and test [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=139&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings!</p>
<p>Now we meet again for the exercise 2. After exercise 1, we are really sure that you guys can solve this problem easily <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p>So, are we ready to rumble? <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p><strong>Exercise 2</strong></p>
<p>Define and test a predicate to read in a series of characters input by the user and output all of those before the first new line or ? character.</p>
<p>Answer :</p>
<p>Well, first of all we have to make the rule for Prolog program. The source code will be like this :</p>
<p><strong>go:-repeat,get0(X),stop(X).<br />
stop(13):-nl.<br />
stop(63):-nl,repeat,get0(X),X=:=13.<br />
stop(X):-put(X),fail.<span id="more-139"></span></strong></p>
<p>We will explain you a little bit about the source code. Just a little bit, because we know that you guys already dig it <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> . The first line is to input the program from user (get0 predicate), then loop it (repeat predicate). After that the get0 predicate will convert it to ASCII numeric. The second and third line is using stop(13) and stop(63)  predicate. Stop is a predicate to stop the process of the program, so if we use stop(13) means that the program will end when user input a blank character, while stop(63) means that the program will end when user input &#8220;?&#8221; character. The last line is using &#8216;put&#8217; predicate. It means the program will display the character that have been inputted by user, converted to ASCII.</p>
<p>Okhaii, let’s go to the Prolog program <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p>1. First of all, you have to write down the following program to notepad, and save as .pl file. For this exercise, we will save it as <strong>loop2.pl</strong></p>
<p><strong><img class="alignnone size-full wp-image-140" title="loop4" src="http://mathmaniacs.files.wordpress.com/2009/12/loop4.jpg?w=495&#038;h=117" alt="" width="495" height="117" /><br />
</strong></p>
<p>2. Open your Prolog, click File&gt;Consult and find the file you’ve just saved it. After you successfully open it, Prolog will manage to show you a successful quote just like the screenshot show.</p>
<p><img class="alignnone size-full wp-image-141" title="loop5" src="http://mathmaniacs.files.wordpress.com/2009/12/loop5.jpg?w=495&#038;h=232" alt="" width="495" height="232" /></p>
<p>3. Let’s proof the question, try the command on your Prolog :</p>
<p style="text-align:center;">go.</p>
<p>After you hit enter, you can type just like the question wanted.</p>
<p>Try to type a name, for example type : Novan.</p>
<p>Then, type : Hari?Alfie.</p>
<p>After you hit enter, the result will come as shown on the screenshot.</p>
<p><img class="alignnone size-full wp-image-142" title="loop6" src="http://mathmaniacs.files.wordpress.com/2009/12/loop6.jpg?w=495&#038;h=232" alt="" width="495" height="232" /></p>
<p>Okhaaii then, that is enough for Exercise 2. We will continue for the next exercise on the next post, so enjoy! <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=139&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop4.jpg" medium="image">
			<media:title type="html">loop4</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop5.jpg" medium="image">
			<media:title type="html">loop5</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop6.jpg" medium="image">
			<media:title type="html">loop6</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>
	</item>
		<item>
		<title>Loops (Exercise 1)</title>
		<link>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-1/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-1/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 05:13:55 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Prolog Tutorials]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=131</guid>
		<description><![CDATA[Greetings! Now we meet again for the fifth tutorial now after you learned about Loops in our Literature Review, it is the time to implement your thoughts to Prolog Program So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=131&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings!</p>
<p>Now we meet again for the fifth tutorial <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> now after you learned about Loops in our Literature Review, it is the time to implement your thoughts to Prolog Program <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p>So, are we ready to rumble? <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p><strong>Excercise 1</strong></p>
<p>Define a predicate to output the values of the squares of the integers from N1 to N2 inclusive and test it with N1 = 6 and N2 = 12.</p>
<p>Answer :</p>
<p>We can find a squared integer from the first input number until the last input number.</p>
<p>Here is the source code :</p>
<p><strong>output_square(N1,N2):-N1&gt;N2.<br />
output_square(N1,N2):- write(N1),write(&#8216; square is &#8216;),Square is N1*N1,<br />
write(Square),nl,M is N1+1,output_square(M,N2).<span id="more-131"></span></strong></p>
<p>We will explain you a little bit about the source code. Just a little bit, because we know that you guys already dig it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . The first line is output_square. It uses to continue the loop if the N1 greater than N2. Second line is the loop session. If the first number (N1) reach the last number (N2) then the program will stop. The last line is to produce the product number M, if it is success, then it will continue by adding N1 with 1 so the program will continue until it reach the end of the last number (N2).</p>
<p>Okhaii, let’s go to the Prolog program <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p>1. First of all, you have to write down the following program to notepad, and save as .pl file. For this exercise, we will save it as <strong>loop1.pl</strong></p>
<p><img class="size-full wp-image-133  alignnone" title="loop1" src="http://mathmaniacs.files.wordpress.com/2009/12/loop1.jpg?w=495&#038;h=146" alt="" width="495" height="146" /></p>
<p><strong> </strong></p>
<p>2. Open your Prolog, click File&gt;Consult and find the file you’ve just saved it. After you successfully open it, Prolog will manage to show you a successful quote just like the screenshot show.</p>
<p><img class="alignnone size-full wp-image-134" title="loop2" src="http://mathmaniacs.files.wordpress.com/2009/12/loop2.jpg?w=495&#038;h=232" alt="" width="495" height="232" /></p>
<p>3. Let’s proof the question, try the command on your Prolog :</p>
<p style="text-align:center;">output_square(6,12).</p>
<p style="text-align:left;">After you hit enter, the result will come as shown on the screenshot.</p>
<p style="text-align:left;"><img class="alignnone size-full wp-image-135" title="loop3" src="http://mathmaniacs.files.wordpress.com/2009/12/loop3.jpg?w=495&#038;h=232" alt="" width="495" height="232" /></p>
<p style="text-align:left;">Okhaaii then, that is enough for Exercise 1. We will continue for the next exercise on the next post, so enjoy! <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=131&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/12/08/loops-exercise-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop1.jpg" medium="image">
			<media:title type="html">loop1</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop2.jpg" medium="image">
			<media:title type="html">loop2</media:title>
		</media:content>

		<media:content url="http://mathmaniacs.files.wordpress.com/2009/12/loop3.jpg" medium="image">
			<media:title type="html">loop3</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>
	</item>
		<item>
		<title>Loops</title>
		<link>http://mathmaniacs.wordpress.com/2009/12/07/loops/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/12/07/loops/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 16:09:45 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Literature Review]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=159</guid>
		<description><![CDATA[Greetings ! Now we have entered our third Literature Review. This time we will discuss about Loops in Prolog. So take your time and enjoy the review LOOPS 6.1 Lopping a Fixed Number of Times Many programming languages provide &#8216;for loops&#8217; which enable a set of instructions to be executed a fixed number of times. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=159&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings !</p>
<p>Now we have entered our third Literature Review. This time we will discuss about Loops in Prolog. So take your time and enjoy the review <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>LOOPS</p>
<p>6.1 Lopping a Fixed Number of Times</p>
<p>Many programming languages provide &#8216;for loops&#8217; which enable a set of instructions to be executed a fixed number of times. No such facility is available in Prolog (directly), but a similar effect can be obtained using recursion, as shown in the example programs below.</p>
<p>loop(0).</p>
<p>loop(N):-N&gt;0,write(&#8216;The value is: &#8216;),write(N),nl,</p>
<p>M is N-1,loop(M).</p>
<p>The <strong>loop </strong>predicate is defined in terms of itself. The second clause can be thought of as: &#8216;to loop from <strong>N</strong>, first write the value of <strong>N</strong>, then subtract one to give <strong>M</strong>, then loop from <strong>M</strong>&#8216;. This process clearly needs to be terminated and this is achieved by the first clause: &#8216;when the argument is zero, do nothing (and hence stop)&#8217;. The first clause can be regarded as a <em>terminating condition </em>for the recursion.</p>
<p><strong>?- loop(6).</strong></p>
<p><strong>The value is: 6</strong></p>
<p><strong>The value is: 5</strong></p>
<p><strong>The value is: 4</strong></p>
<p><strong>The value is: 3</strong></p>
<p><strong>The value is: 2</strong></p>
<p><strong>The value is: 1</strong></p>
<p><strong>Yes<span id="more-159"></span></strong><strong> </strong></p>
<p>Note the use of the two goals M is N-1,loop(M) in the second clause for the loop predicate. The obvious alternative of loop(N-1) will not work. Prolog only evaluates expressions such as N-1 when evaluating goals with functor is or one of the relational operators, as described in Chapter 4. If N-1 is used as an argument of a predicate it is taken to mean the term with infix operator &#8211; (i.e. a minus sign) and arguments N and 1. This is most unlikely to be what is intended!</p>
<p>Example 2</p>
<p>The next program outputs integers from <em>First </em>to <em>Last </em>inclusive.</p>
<p>/* output integers from First to Last inclusive */</p>
<p>output_values(Last,Last):- write(Last),nl,</p>
<p>write(&#8216;end of example&#8217;),nl.</p>
<p>output_values(First,Last):-First=\=Last,write(First),</p>
<p>nl,N is First+1,output_values(N,Last).</p>
<p>Here <strong>output_values </strong>has two arguments, which can be read as &#8216;output the integers from <em>First </em>to <em>Last </em>inclusive&#8217;. The loop terminates when both arguments are the same.</p>
<p><strong>?- output_values(5,12).</strong></p>
<p><strong>5</strong></p>
<p><strong>6</strong></p>
<p><strong>7</strong></p>
<p><strong>8</strong></p>
<p><strong>9</strong></p>
<p><strong>10</strong></p>
<p><strong>11</strong></p>
<p><strong>12</strong></p>
<p><strong>end of example</strong></p>
<p><strong>yes</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>Example 3</p>
<p>Define a predicate to find the sum of the integers from 1 to N (say for N = 100).</p>
<p>It is natural to think of this procedurally, i.e. start with 1, then add 2, then add 3, then add 4, … , then add 100. However the process is much easier to program if reexpressed declaratively in terms of itself.</p>
<p>The sum of the first 100 integers is the sum of the first 99 integers, plus 100.</p>
<p>The sum of the first 99 integers is the sum of the first 98 integers, plus 99.</p>
<p>The sum of the first 98 integers is the sum of the first 97 integers, plus 98.</p>
<p>…………………………………………………………………………….</p>
<p>The sum of the first 3 integers is the sum of the first 2 integers, plus 3.</p>
<p>The sum of the first 2 integers is the sum of the first 1 integers, plus 2.</p>
<p>The sum of the first 1 integers is one.</p>
<p>There are two distinct cases to consider: the <em>general case</em>: &#8216;the sum of the first N integers is the sum of the first N-1 integers, plus N&#8217; and the <em>terminating case</em>: &#8216;the sum of the first 1 integers is 1&#8242;. This leads directly to the recursive definition:</p>
<p>/* sum the integers from 1 to N (the first argument)</p>
<p>inclusive */</p>
<p>sumto(1,1).</p>
<p>sumto(N,S):-N&gt;1,N1 is N-1,sumto(N1,S1),S is S1+N.</p>
<p><strong> </strong></p>
<p><strong>?- sumto(100,N).</strong></p>
<p><strong>N = 5050</strong></p>
<p><strong>?- sumto(1,1).</strong></p>
<p><strong>yes</strong></p>
<p>Note that using the additional variable <strong>N1 </strong>for holding the value of <strong>N-1 </strong>is essential. Writing <strong>sumto(N-1,S1) </strong>etc. instead would not work correctly. <strong>N-1 </strong>is a term, not a numerical value.</p>
<p>Example 4</p>
<p>Define a predicate to output the squares of the first N integers, one per line.</p>
<p>This can most easily be programmed if first recast in a recursive form, as follows.</p>
<p>To output the squares of the first N integers, output the squares of the first N-1 and then output N²</p>
<p>To output the squares of the first N-1 integers, output the squares of the first N-2 and then output (N-1)²</p>
<p>To output the squares of the first N-2 integers, output the squares of the first N-3 and then output (N-2)²</p>
<p>……………………………………………………………………………………….</p>
<p>To output the squares of the first 3 integers, output the squares of the first 2 and then output 3²</p>
<p>To output the squares of the first 2 integers, output the squares of the first 1 and then output 2²</p>
<p>To output the squares of the first 1 integers, output the number 1</p>
<p>Here the general case is &#8216;to output the squares of the first N integers, output the squares of the first N-1 and then output N²&#8217; and the terminating case is &#8216;to output the squares of the first 1 integers, output the number 1&#8242;. This leads to the following two-clause program.</p>
<p>/* output the first N squares, one per line */</p>
<p>writesquares(1):-write(1),nl.</p>
<p>writesquares(N):-N&gt;1,N1 is N-1,writesquares(N1),</p>
<p>Nsq is N*N,write(Nsq),nl.</p>
<p><strong> </strong></p>
<p><strong>?- writesquares(6).</strong></p>
<p><strong>1</strong></p>
<p><strong>4</strong></p>
<p><strong>9</strong></p>
<p><strong>16</strong></p>
<p><strong>25</strong></p>
<p><strong>36</strong></p>
<p><strong>yes</strong></p>
<p>Example 5</p>
<p>The following program reads the first 6 terms from a specified file and writes them to the current output stream. It uses a &#8216;counting down&#8217; method, in a similar way to Example 1.</p>
<p>read_six(Infile):-seeing(S),see(Infile),</p>
<p>process_terms(6),seen,see(S).</p>
<p>process_terms(0).</p>
<p>process_terms(N):-N&gt;0,read(X),write(X),nl,N1 is N-1,</p>
<p>process_terms(N1).</p>
<p>6.2 Lopping Until a Condition Is Satisfied</p>
<p>Many languages have an &#8216;until loop&#8217; which enables a set of instructions to be executed repeatedly until a given condition is met. Again, no such facility is available directly in Prolog, but a similar effect can be obtained in several ways.</p>
<p>6.2.1 Recursion</p>
<p>The first example below shows the use of recursion to read terms entered by the user from the keyboard and output them to the screen, until <em>end </em>is encountered.</p>
<p>go:-loop(start). /* start is a dummy value used to get</p>
<p>the looping process started.*/</p>
<p>loop(end).</p>
<p>loop(X):-X\=end,write(&#8216;Type end to end&#8217;),read(Word),</p>
<p>write(&#8216;Input was &#8216;),write(Word),nl,loop(Word).</p>
<p><strong>?- go.</strong></p>
<p><strong>Type end to end: university.</strong></p>
<p><strong>Input was university</strong></p>
<p><strong>Type end to end: of.</strong></p>
<p><strong>Input was of</strong></p>
<p><strong>Type end to end: portsmouth.</strong></p>
<p><strong>Input was portsmouth</strong></p>
<p><strong>Type end to end: end.</strong></p>
<p><strong>Input was end</strong></p>
<p><strong>yes</strong></p>
<p>Using the disjunction operator <strong>;/2 </strong>which was defined in Section 4.4 the above program can be rewritten as a single clause.</p>
<p>loop:-write(&#8216;Type end to end&#8217;),read(Word),</p>
<p>write(&#8216;Input was &#8216;),write(Word),nl,</p>
<p>(Word=end;loop).</p>
<p>The &#8216;disjunctive goal&#8217; <strong>(Word=end;loop) </strong>succeeds if variable <em>Word </em>is bound to the atom <em>end</em>. If not, the system attempts to satisfy the goal <strong>loop </strong>recursively.</p>
<p><strong>?- loop.</strong></p>
<p><strong>Type end to end: university.</strong></p>
<p><strong>Input was university</strong></p>
<p><strong>Type end to end: of.</strong></p>
<p><strong>Input was of</strong></p>
<p><strong>Type end to end: portsmouth.</strong></p>
<p><strong>Input was portsmouth</strong></p>
<p><strong>Type end to end: end.</strong></p>
<p><strong>Input was end</strong></p>
<p><strong>yes</strong></p>
<p><strong> </strong></p>
<p>This recursive program repeatedly prompts the user to enter a term until either <em>yes </em>or <em>no </em>is entered.</p>
<p>get_answer(Ans):-write(&#8216;Enter answer to question&#8217;),</p>
<p>nl,get_answer2(Ans).</p>
<p>get_answer2(Ans):-</p>
<p>write(&#8216;answer yes or no&#8217;),</p>
<p>read(A),</p>
<p>((valid(A),Ans=A,write(&#8216;Answer is &#8216;),</p>
<p>write(A),nl);get_answer2(Ans)).</p>
<p>valid(yes). valid(no).</p>
<p><strong>?- get_answer(Myanswer).</strong></p>
<p><strong>Enter answer to question</strong></p>
<p><strong>answer yes or no: maybe.</strong></p>
<p><strong>answer yes or no: possibly.</strong></p>
<p><strong>answer yes or no: yes.</strong></p>
<p><strong>Answer is yes</strong></p>
<p><strong>Myanswer = yes</strong></p>
<p><strong>6.2.2 Using the &#8216;repeat&#8217; Predicate</strong></p>
<p><strong> </strong></p>
<p>Another method that is often used is based on the built-in predicate <strong>repeat</strong>. The goal <strong>repeat </strong>does not repeat anything; it merely succeeds whenever it is called. The great value of <strong>repeat </strong>is that it also succeeds (as many times as necessary) on backtracking. The effect of this, as for any other goal succeeding, is to change the order of evaluating goals from &#8216;right to left&#8217; (i.e. backtracking) back to &#8216;left-to-right&#8217;. This can be used to create a looping effect, as shown in the examples below.</p>
<p>get_answer(Ans):-</p>
<p>write(&#8216;Enter answer to question&#8217;),nl,</p>
<p>repeat,write(&#8216;answer yes or no&#8217;),read(Ans),</p>
<p>valid(Ans),write(&#8216;Answer is &#8216;),write(Ans),nl.</p>
<p>valid(yes). valid(no).</p>
<p>The first five goals in the body of <strong>get_answer </strong>will always succeed. Evaluating the fifth goal: <strong>read(Ans) </strong>will prompt the user to enter a term. If the term input is anything but <em>yes </em>or <em>no</em>, say <em>unsure</em>, the following goal <strong>valid(Ans) </strong>will fail. Prolog will then backtrack over <strong>read(Ans) </strong>and <strong>write(&#8216;answer yes or no&#8217;)</strong>, both of which are <em>unresatisfiable</em>, i.e. will always fail on backtracking.</p>
<p>Backtracking will then reach the predicate <strong>repeat </strong>and succeed, causing evaluation to proceed forward (left-to-right) again, with <strong>write(&#8216;answer yes or no&#8217;) </strong>and <strong>read(Ans) </strong>both succeeding, followed by a further evaluation of <strong>valid(Ans)</strong>.</p>
<p>Depending on the value of <strong>Ans</strong>, i.e. the user&#8217;s input, the <strong>valid(Ans) </strong>goal will either fail, in which case Prolog will backtrack as far as <strong>repeat</strong>, as before, or it will succeed in which case the final three goals <strong>write(&#8216;Answer is&#8217;)</strong>, <strong>write(Ans) </strong>and <strong>nl </strong>will all succeed. The overall effect is that the two goals <strong>write(&#8216;answer yes or no&#8217;) </strong>and <strong>read(Ans) </strong>are called repeatedly until the terminating condition <strong>valid(Ans) </strong>is satisfied, effectively creating a loop between <strong>repeat </strong>and <strong>valid(Ans)</strong>.</p>
<p><strong>?- get_answer(X).</strong></p>
<p><strong>Enter answer to question</strong></p>
<p><strong>answer yes or no: unsure.</strong></p>
<p><strong>answer yes or no: possibly.</strong></p>
<p><strong>answer yes or no: no.</strong></p>
<p><strong>answer is no</strong></p>
<p><strong>X = no</strong></p>
<p><strong> </strong></p>
<p>Logic Programing With Prolog</p>
<p>Goals to the left of <strong>repeat </strong>in the body of a clause will never be reached on backtracking.</p>
<p>The next program reads a sequence of terms from a specified file and outputs them to the current output stream until the term <em>end </em>is encountered.</p>
<p>readterms(Infile):-</p>
<p>seeing(S),see(Infile),</p>
<p>repeat,read(X),write(X),nl,X=end,</p>
<p>seen,see(user).</p>
<p>In a similar way to the previous program, this effectively defines a loop between the goals <strong>repeat </strong>and <strong>X=end</strong>.</p>
<p>If file <em>myfile.txt </em>contains the lines</p>
<p>&#8216;first term&#8217;. &#8216;second term&#8217;.</p>
<p>&#8216;third term&#8217;. &#8216;fourth term&#8217;.</p>
<p>&#8216;fifth term&#8217;. &#8216;sixth term&#8217;.</p>
<p>&#8216;seventh term&#8217;.</p>
<p>&#8216;eighth term&#8217;.</p>
<p>end.</p>
<p>calling <strong>readterms </strong>will produce the following output</p>
<p><strong>?- readterms(&#8216;myfile.txt&#8217;).</strong></p>
<p><strong>first term</strong></p>
<p><strong>second term</strong></p>
<p><strong>third term</strong></p>
<p><strong>fourth term</strong></p>
<p><strong>fifth term</strong></p>
<p><strong>sixth term</strong></p>
<p><strong>seventh term</strong></p>
<p><strong>eighth term</strong></p>
<p><strong>end</strong></p>
<p><strong>yes</strong></p>
<p><strong> </strong></p>
<p>This program shows how to implement a menu structure which loops back repeatedly to request more input. Entering <strong>go </strong>at the prompt causes Prolog to output a menu from which the user can choose activities one at a time until option <em>d </em>is chosen. Note that all inputs are terms and so must be followed by a full stop character.</p>
<p>go:- write(&#8216;This shows how a repeated menu works&#8217;),</p>
<p>menu.</p>
<p>menu:-nl,write(&#8216;MENU&#8217;),nl,</p>
<p>write(&#8216;a. Activity A&#8217;),nl,write(&#8216;b. Activity B&#8217;),nl,</p>
<p>write(&#8216;c. Activity C&#8217;),nl,write(&#8216;d. End&#8217;),nl,</p>
<p>read(Choice),nl,choice(Choice).</p>
<p>choice(a):-write(&#8216;Activity A chosen&#8217;),menu.</p>
<p>choice(b):-write(&#8216;Activity B chosen&#8217;),menu.</p>
<p>choice(c):-write(&#8216;Activity C chosen&#8217;),menu.</p>
<p>choice(d):-write(&#8216;Goodbye!&#8217;),nl.</p>
<p>choice(_):-write(&#8216;Please try again!&#8217;),menu.</p>
<p><strong>?- go.</strong></p>
<p><strong>This shows how a repeated menu works</strong></p>
<p><strong>MENU</strong></p>
<p><strong>a. Activity A</strong></p>
<p><strong>b. Activity B</strong></p>
<p><strong>c. Activity C</strong></p>
<p><strong>d. End</strong></p>
<p><strong>: b.</strong></p>
<p><strong>Activity B chosen</strong></p>
<p><strong>MENU</strong></p>
<p><strong>a. Activity A</strong></p>
<p><strong>b. Activity B</strong></p>
<p><strong>c. Activity C</strong></p>
<p><strong>d. End</strong></p>
<p><strong>: xxx.</strong></p>
<p><strong>Please try again!</strong></p>
<p><strong>MENU</strong></p>
<p><strong>a. Activity A</strong></p>
<p><strong>b. Activity B</strong></p>
<p><strong>c. Activity C</strong></p>
<p><strong>d. End</strong></p>
<p><strong>: d.</strong></p>
<p><strong>Goodbye!</strong></p>
<p><strong>Yes</strong></p>
<p><strong> </strong></p>
<p><strong>6.3 </strong><strong>Backtracking with Failure</strong></p>
<p><strong> </strong></p>
<p>As the name implies, the predicate <strong>fail </strong>always fails, whether on &#8216;standard&#8217; evaluation left-to-right or on backtracking. Advantage can be taken of this, combined with Prolog&#8217;s automatic backtracking, to search through the database to find all the clauses with a specified property.</p>
<p><strong>6.3.1 Searching the Prolog Database</strong></p>
<p><strong> </strong></p>
<p>Supposing the database contains clauses such as</p>
<p>dog(fido).</p>
<p>dog(fred).</p>
<p>dog(jonathan).</p>
<p>Each <strong>dog </strong>clause can be processed in turn using the <strong>alldogs </strong>predicate defined below.</p>
<p>alldogs:-dog(X),write(X),write(&#8216; is a dog&#8217;),nl,fail.</p>
<p>alldogs.</p>
<p>Calling <strong>alldogs </strong>will cause <strong>dog(X) </strong>to be matched with the <strong>dog </strong>clauses in the database. Initially <strong>X </strong>will be bound to <em>fido </em>and &#8216;fido is a dog&#8217; will be output. The final goal in the first clause of the <strong>alldogs </strong>predicate will then cause evaluation to fail. Prolog will then backtrack over <strong>nl </strong>and the two <strong>write </strong>goals (all of which are unresatisfiable) until it reaches <strong>dog(X)</strong>. This goal will succeed for a second time causing <strong>X </strong>to be bound to <em>fred</em>.</p>
<p>This process will continue until <em>fido</em>, <em>fred </em>and <em>jonathan </em>have all been output, when evaluation will again fail. This time the call to <strong>dog(X) </strong>will also fail as there are no further <strong>dog </strong>clauses in the database. This will cause the first clause for <strong>alldogs </strong>to fail and Prolog to examine the second clause of <strong>alldogs</strong>. This will succeed and evaluation will stop.</p>
<p>The effect is to loop through the database finding all possible values of <strong>X </strong>that satisfy the goal <strong>dog(X)</strong>.</p>
<p><strong>?- alldogs.</strong></p>
<p><strong>fido is a dog</strong></p>
<p><strong>fred is a dog</strong></p>
<p><strong>jonathan is a dog</strong></p>
<p><strong>yes</strong></p>
<p><strong> </strong></p>
<p>Note the importance of the second clause of the <strong>alldogs </strong>predicate. It is there to ensure that, after the database has been searched, the goal succeeds. With only the first line, any call to <strong>alldogs </strong>will eventually fail.</p>
<p>alldogs:-dog(X),write(X),write(&#8216; is a dog&#8217;),nl,fail.</p>
<p><strong>?- alldogs.</strong></p>
<p><strong>fido is a dog</strong></p>
<p><strong>fred is a dog</strong></p>
<p><strong>jonathan is a dog</strong></p>
<p><strong>no</strong></p>
<p><strong> </strong></p>
<p>The next program is designed to search a database containing clauses representing the name, age, place of residence and occupation of a number of people.</p>
<p>If the database contains these five clauses</p>
<p>person(john,smith,45,london,doctor).</p>
<p>person(martin,williams,33,birmingham,teacher).</p>
<p>person(henry,smith,26,manchester,plumber).</p>
<p>person(jane,wilson,62,london,teacher).</p>
<p>person(mary,smith,29,glasgow,surveyor).</p>
<p>The names of all the teachers can be found using the <strong>allteachers </strong>predicate.</p>
<p>allteachers:-person(Forename,Surname,_,_,teacher),</p>
<p>write(Forename),write(&#8216; &#8216;),write(Surname),nl,</p>
<p>fail.</p>
<p>allteachers.</p>
<p>The effect of using backtracking with failure in this case is to find all the teachers in the database.</p>
<p><strong>?- allteachers.</strong></p>
<p><strong>martin williams</strong></p>
<p><strong>jane wilson</strong></p>
<p><strong>yes</strong></p>
<p><strong> </strong></p>
<p>If the second clause of <strong>allteachers </strong>were omitted, both teachers would still be found but the evaluation of <strong>allteachers </strong>would end with failure. This is of little or no importance when a goal is entered at the system prompt, but if <strong>allteachers </strong>were used as a goal in the body of a rule it would obviously be desirable to ensure that it always succeeded.</p>
<p>It should be noted that it is not always necessary to use &#8216;backtracking with failure&#8217; to search the database. For example, the predicate <strong>somepeople/0 </strong>defined below will find all the people in the database given previously, down to <em>williams</em>, using only standard backtracking.</p>
<p>somepeople:-person(Forename,Surname,_,_,_),</p>
<p>write(Forename),write(&#8216; &#8216;),write(Surname),nl,</p>
<p>Surname=williams.</p>
<p>somepeople.</p>
<p>The goal <strong>Surname=williams </strong>succeeds if the variable <em>Surname </em>is bound to <em>williams</em>. If not, it fails. The effect is to search the database down to and including the <strong>person </strong>clause with second argument <em>williams</em>.</p>
<p><strong>?- somepeople.</strong></p>
<p><strong>john smith</strong></p>
<p><strong>martin williams</strong></p>
<p><strong>yes</strong></p>
<p><strong> </strong></p>
<p><strong>6.3.2 Finding Multiple Solutions</strong></p>
<p><strong> </strong></p>
<p>Backtracking with failure can also be used to find all the ways of satisfying a goal. Suppose that a predicate <strong>findroute(Town1,Town2,Route) </strong>finds a route <em>Route </em>between two towns <em>Town1 </em>and <em>Town2</em>. The details of this predicate are irrelevant here. It may be assumed that <em>Town1 </em>and <em>Town2 </em>are atoms and that <em>Route </em>is a list.</p>
<p>Backtracking with failure can then be used to find all possible routes between <em>Town1 </em>and <em>Town2 </em>and write out each one on a separate line, as follows:</p>
<p>find_all_routes(Town1,Town2):-</p>
<p>findroute(Town1,Town2,Route),</p>
<p>write(&#8216;Possible route: &#8216;),write(Route),nl,fail.</p>
<p>find_all_routes(_,_).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/159/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=159&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/12/07/loops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>
	</item>
		<item>
		<title>Input and Output in Prolog (Exercise 2)</title>
		<link>http://mathmaniacs.wordpress.com/2009/11/25/input-and-output-in-prolog-exercise-2/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/11/25/input-and-output-in-prolog-exercise-2/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 18:25:41 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Prolog Tutorials]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=118</guid>
		<description><![CDATA[Greetings! Now we meet again for the exercise 2. After exercise 1, we are really sure that you guys can solve this problem easily So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy Exercise 2 Define a predicate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=118&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings!</p>
<p>Now we meet again for the exercise 2. After exercise 1, we are really sure that you guys can solve this problem easily <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>So, are we ready to rumble? <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p><strong>Exercise 2</strong></p>
<p>Define a predicate copyterms which reads all the terms in a text file and outputs them as terms to another text file one by one on separate lines. The output file should be in a format suitable for use as the input file in a subsequent call of copyterms. Thus for example if the input file contained</p>
<p><strong>&#8216;first term&#8217;. &#8216;second term&#8217;.<br />
&#8216;third term&#8217;.<br />
fourth. &#8216;fifth term&#8217;.<br />
sixth.</strong></p>
<p>The output file would contain</p>
<p><strong>&#8216;first term&#8217;.<br />
&#8216;second term&#8217;.<br />
&#8216;third term&#8217;.<br />
fourth.<br />
&#8216;fifth term&#8217;.<br />
sixth.<span id="more-118"></span></strong></p>
<p>Answer :</p>
<p>1. First of all, you have to write down the following input to notepad, and save as txt file. This is because we wanted to create the input file. Write it down and save it to C:/ path with <strong>infile.txt</strong> name.</p>
<p><img class="alignnone" title="op4" src="http://acciokerry.googlepages.com/op4.jpg" alt="" width="444" height="175" /></p>
<p>2. Now let&#8217;s make the rule of prolog. Open your notepad again, write down this predicate</p>
<p><strong>copyterms(Infile,Outfile):-<br />
seeing(S),telling(T),<br />
see(Infile),tell(Outfile),<br />
copy,<br />
seen,see(S),told,tell(T).<br />
copy:-read(X),process(X).<br />
process(end_of_file).<br />
process(X):-<br />
X\=end_of_file,<br />
write(X),write(&#8216;.&#8217;),nl,copy.</strong></p>
<p>save it to your notepad, and name it as <strong>inout.pl</strong></p>
<p><strong><img class="alignnone" title="op5" src="http://acciokerry.googlepages.com/op5.jpg" alt="" width="444" height="165" /><br />
</strong></p>
<p>3. Open your Prolog, click File&gt;Consult and find the file you’ve just saved it. After you successfully open it, Prolog will manage to show you a successful quote just like the screenshot show.</p>
<p><img class="alignnone" title="op6" src="http://acciokerry.googlepages.com/op6.jpg" alt="" width="500" height="233" /></p>
<p>4. Let’s proof the question, try the command on your Prolog :</p>
<p style="text-align:center;"><strong>copyterms(&#8216;C:/infile.txt&#8217;,'C:/outfile.txt&#8217;).</strong></p>
<p style="text-align:left;">After you hit enter, it will display just like the screenshot below. It means, with the command you have successfully make an output file from the input infile.txt you made before.</p>
<p style="text-align:left;"><img class="alignnone" title="op7" src="http://acciokerry.googlepages.com/op7.jpg" alt="" width="486" height="228" /></p>
<p style="text-align:left;">5. Now let&#8217;s check the result of the file named outfile.txt. Go to the C:/ path, and you will find the file. Open it, and it will display just like the screenshot below.</p>
<p style="text-align:left;"><img class="alignnone" title="op8" src="http://acciokerry.googlepages.com/op8.jpg" alt="" width="466" height="298" /></p>
<p style="text-align:left;">
<p style="text-align:left;"><img class="alignnone" title="op9" src="http://acciokerry.googlepages.com/op9.jpg" alt="" width="486" height="174" /></p>
<p style="text-align:left;">
<p style="text-align:left;">
<p style="text-align:left;">Easy, right? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  That is all for the exercise. We will continue with the next post for the Exercise 3. So enjoy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/118/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/118/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/118/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=118&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/11/25/input-and-output-in-prolog-exercise-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op4.jpg" medium="image">
			<media:title type="html">op4</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op5.jpg" medium="image">
			<media:title type="html">op5</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op6.jpg" medium="image">
			<media:title type="html">op6</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op7.jpg" medium="image">
			<media:title type="html">op7</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op8.jpg" medium="image">
			<media:title type="html">op8</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op9.jpg" medium="image">
			<media:title type="html">op9</media:title>
		</media:content>
	</item>
		<item>
		<title>Input and Output (Exercise 1)</title>
		<link>http://mathmaniacs.wordpress.com/2009/11/25/input-and-output-exercise-1/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/11/25/input-and-output-exercise-1/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 16:23:36 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Prolog Tutorials]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=108</guid>
		<description><![CDATA[Greetings! Now we meet again for the fourth tutorial now after you learned about Input and Output in our Literature Review, it is the time to implement your thoughts to Prolog Program So, are we ready to rumble? We will show you every step and there is screenshots as additional suplements. So don’t worry, it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=108&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Greetings!</p>
<p>Now we meet again for the fourth tutorial <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> now after you learned about Input and Output in our Literature Review, it is the time to implement your thoughts to Prolog Program <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p>So, are we ready to rumble? <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /> We will show you every step and there is screenshots as additional suplements. So don’t worry, it will be easy <img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif?w=495" alt=":D" /></p>
<p><strong>Excercise 1</strong></p>
<p>Define a predicate makelower/0 which reads in a line of characters from the keyboard and outputs it again as a single line with any upper case letters converted to lower case. (The ASCII values of the characters a, z, A and Z are 97, 122, 65 and 90, respectively.). Thus the following would be a typical use of makelower:<br />
<strong>?- makelower.<br />
: This is an Example 123 inCLUDing numbers and symbols +-*/@[] XYz<br />
this is an example 123 including numbers and symbols +-*/@[] xyz<span id="more-108"></span></strong></p>
<p>Answer :</p>
<p>Well, first of all we have to make the rule for Prolog program. The source code will be like this :</p>
<p><strong>makelower:- get0(X),process(X).<br />
process(13).<br />
process(X):- X=\=13,case(X,Y),put(Y),makelower.<br />
case(X,Y):- X &gt; 64, X &lt; 91, Y is X+32.<br />
case(X,Y):- Y is X+0.</strong></p>
<p>We use the get0 to convert the input character. Then, we use case (X,Y) to conclude the range of ASCII.</p>
<p>Okhaii, let&#8217;s go to the Prolog program <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>1. First of all, you have to write down the following program to notepad, and save as .pl file. For this exercise, we will save it as <strong>makelower.pl</strong></p>
<p><strong><img class="alignnone" title="op1" src="http://acciokerry.googlepages.com/op1.jpg" alt="" width="554" height="261" /><br />
</strong></p>
<p>2. Open your Prolog, click File&gt;Consult and find the file you’ve just saved it. After you successfully open it, Prolog will manage to show you a successful quote just like the screenshot show.</p>
<p><img class="alignnone" title="op2" src="http://acciokerry.googlepages.com/op2.jpg" alt="" width="500" height="262" /></p>
<p>3. Let’s proof the question, try the command on your Prolog :</p>
<p style="text-align:center;">makelower.</p>
<p style="text-align:left;">After you hit enter, you can type just like the question wanted.</p>
<p style="text-align:center;"><strong>This is an Example 123 inCLUDing numbers and symbols +-*/@[] XYz</strong></p>
<p style="text-align:left;"><strong><br />
</strong>After you hit enter, the result will come as shown on the screenshot.</p>
<p style="text-align:left;"><img class="alignnone" title="op3" src="http://acciokerry.googlepages.com/op3.jpg" alt="" width="486" height="256" /></p>
<p style="text-align:left;">Okhaaii then, that is enough for Exercise 1. We will continue for the next exercise on the next post, so enjoy! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=108&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/11/25/input-and-output-exercise-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" medium="image">
			<media:title type="html">:D</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op1.jpg" medium="image">
			<media:title type="html">op1</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op2.jpg" medium="image">
			<media:title type="html">op2</media:title>
		</media:content>

		<media:content url="http://acciokerry.googlepages.com/op3.jpg" medium="image">
			<media:title type="html">op3</media:title>
		</media:content>
	</item>
		<item>
		<title>Input And Output in Prolog</title>
		<link>http://mathmaniacs.wordpress.com/2009/11/25/98/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/11/25/98/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 15:09:41 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Prolog Tutorials]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=98</guid>
		<description><![CDATA[Chapter 5 Input and Output Outputting Terms The main built-in predicate provided for outputting terms is write/1, the write/1 predicate takes a single argument, which must be a valid Prolog term. The built-in predicate nl/0  has also been used many times, evaluating a nl goal causes a new line to be output to the current [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=98&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><strong> Chapter 5 Input and Output</strong></h2>
<p><strong> </strong></p>
<ul>
<li><strong>Outputting Terms</strong></li>
</ul>
<p>The main built-in predicate provided for outputting terms is write/1, the write/1 predicate takes a single argument, which must be a valid Prolog term. The built-in predicate nl/0  has also been used many times, evaluating a nl goal causes a new line to be output to the current output stream.</p>
<p>Examples :</p>
<p>?- write(26),nl.</p>
<p>26</p>
<p>yes</p>
<p>?- write(&#8216;a string of characters&#8217;),nl.</p>
<p>a string of characters</p>
<p>yes</p>
<p><strong><em>Note </em></strong>that atoms that have to be quoted on input (e.g. &#8216;Paul&#8217;, &#8216;hello world&#8217;) are not quoted when output using  write. If it is important to output the quotes, the writeq/1  predicate can be used. It is identical to write/1 except that atoms that need quotes for input are output between quotes (other atoms are not).</p>
<p>Examples :</p>
<p>?- writeq(&#8216;a string of characters&#8217;),nl.</p>
<p>&#8216;a string of characters&#8217;</p>
<p>yes</p>
<p>?-writeq(dog),nl.</p>
<p>dog</p>
<p>yes</p>
<ul>
<li><strong>Inputting Terms</strong></li>
</ul>
<p>The built-in predicate read/1 is provided to input terms. It takes a single argument, which must be a variable. In the input stream, the term must be followed by a dot (&#8216;.&#8217;) and at least one white space character, such as space or newline.</p>
<p><strong><em>Note</em></strong> that for input from the keyboard (only) a prompt character such as a colon will usually be displayed to indicate that user input is required. It may be necessary to press the &#8216;return&#8217; key before Prolog will accept the input. Both of these do not apply to input from files. If the variable is unbound (which is usually the case) it is bound to the input value.<span id="more-98"></span></p>
<p>Examples :</p>
<p>?- read(X</p>
<p>: jim.</p>
<p>X = jim</p>
<p>?- read(X</p>
<p>: 26.</p>
<p>X = 26</p>
<p>If the argument variable is already bound (which for most users is far more likely to occur by mistake than by design), the goal succeeds if and only if the input term is identical to the previously bound value.</p>
<p>Examples :</p>
<p>?- X=fred,read(X).</p>
<p>: jim.</p>
<p>no</p>
<p>?- X=fred,read(X).</p>
<p>: fred.</p>
<p>X = fred</p>
<ul>
<li><strong>Input and Output Using Characters</strong></li>
</ul>
<p>Although input and output of terms is straightforward, the use of quotes and full stops can be cumbersome and is not always suitable. it is necessary to know about the ASCII value of a character.</p>
<p>All printing characters and many non-printing characters (such as space and tab) have a corresponding ASCII (American Standard Code for Information Interchange) value, which is an integer from 0 to 255.</p>
<ul>
<li><strong>Outputting Characters</strong></li>
</ul>
<p>Characters are output using the built-in predicate  put/1. The predicate takes a single argument, which must be a number from 0 to 255 or an expression that evaluates to an integer in that range.</p>
<p>Evaluating a  put goal causes a single character to be output to the current output stream. This is the character corresponding to the numerical value (ASCII value) of its argument, for examples :</p>
<p>?- put(97),nl.</p>
<p>a</p>
<p>yes</p>
<p>?- put(122),nl.</p>
<p>z</p>
<p>yes</p>
<ul>
<li><strong>Inputting Characters</strong></li>
</ul>
<p>Two built-in predicates are provided to input a single character: get0/1 and get/1. The get0 predicate takes a single argument, which must be a variable. Evaluating a get0 goal causes a character to be read from the current input stream. The variable is then unified with the ASCII value of this character.</p>
<p><strong><em>Note</em></strong> that for input from the keyboard (only) a prompt character such as a colon will usually be displayed to indicate that user input is required. It may be necessary to press the &#8216;return&#8217; key before Prolog will accept the input. Both of these also apply to the get predicate described below but do not apply to input from files.</p>
<p>Assuming the argument variable is unbound (which will usually be the case), it bound to the ASCII value of the input character.</p>
<p>Examples :</p>
<p>?- get0(N).</p>
<p>: a</p>
<p>N = 97</p>
<p>?- get0(N).</p>
<p>: Z</p>
<p>N = 90</p>
<p>If the argument variable is already bound, the goal succeeds if and only if it has a numerical value that is equal to the ASCII value of the input character. Examples :</p>
<p>?- get0(X).</p>
<p>: a</p>
<p>X = 97</p>
<p>?- M is 41,get0(M).</p>
<p>: )</p>
<p>M = 41</p>
<p>The get predicate takes a single argument, which must be a variable. Evaluating a get goal causes the next non-white-space character (i.e. character with an ASCII value less than or equal to 32) to be read from the current input stream. The variable is then unified with the ASCII value of this character in the same way as for get0.</p>
<p>Examples :</p>
<p>?- get(X).</p>
<p>: Z</p>
<p>X = 90</p>
<p>?- get(M).</p>
<p>:           Z</p>
<p>M = 90</p>
<h3><strong>Using Characters : Examples</strong></h3>
<p>The predicate <strong>readin</strong> is defined <em>recursively.</em> This proses goes on indefinitely until aa * character is read. Example :</p>
<p>Readin :- get0(X),proses(X).</p>
<p>Proses (42).</p>
<p>Proses (X) :- X=\=42, write (X) ,nl, readdin.</p>
<p><strong>?- readin.</strong></p>
<p><strong>*Prolog Example *</strong></p>
<p><strong>80</strong></p>
<p><strong>114</strong></p>
<p><strong>108</strong></p>
<p><strong>32</strong></p>
<p><strong>69</strong></p>
<p><strong>120</strong></p>
<p><strong>97</strong></p>
<p><strong>109</strong></p>
<p><strong>112</strong></p>
<p><strong>108</strong></p>
<p><strong>101</strong></p>
<p><strong>Yes</strong></p>
<p><strong> </strong></p>
<p>The next example is the extended version of one above.  The <strong>count</strong> predicate is defined wiht two arguments which can be read as the numbe of characters counted so far and the total number of the character before the *. Example :</p>
<p>go (Total) :- count(0,Total.</p>
<p>count(Oldcount, Result).</p>
<p>process($(42,Oldcount, Oldcount).</p>
<p>process((X,Output,Result) :- X=|\ = 42,New is Oldcount + 1 (Vew,result).</p>
<p><strong>?- go(T).</strong></p>
<p><strong>:The time has come the walrus said*</strong></p>
<p><strong>T=33</strong></p>
<p><strong>?- got(T).</strong></p>
<p><strong>:*</strong></p>
<p><strong>T=0.</strong></p>
<p>The final example is a recursive program, based on the previous two that read in a series of characters ending with * and count the number of vowels. the two arguments of the <strong>count </strong>predicate can be interpreted as &#8216;the number of vowels so far&#8217; and &#8216;the total number of vowels&#8217;. The three arguments of the <strong>process </strong>predicate can be read as &#8216;the ASCII value of an input character&#8217;, &#8216;the number of vowels up to but not including that character&#8217; and &#8216;the total number of vowels&#8217;, respectively. The first two arguments of the <strong>processChar </strong>predicate can be interpreted in the same way as for <strong>process</strong>, but the third argument is &#8216;the number of vowels up to and including the character (first argument)&#8217;.</p>
<p>Go (Vowels) :-count (0,Vowels).</p>
<p>count(Oldvowels,Totvowels):-</p>
<p>get0(X),process(X,Oldvowels,Totvowels).</p>
<p>process(42,Oldvowels,Oldvowels).</p>
<p>process(X,Oldvowels,Totalvowels):-</p>
<p>X=\=42,processChar(X,Oldvowels,New),</p>
<p>count(New,Totalvowels).</p>
<p>processChar(X,Oldvowels,New):-vowel(X),</p>
<p>New is Oldvowels+1.</p>
<p>processChar(X,Oldvowels,Oldvowels).</p>
<p>vowel(65). /* A */</p>
<p>vowel(69). /* E */</p>
<p>vowel(73). /* I */</p>
<p>vowel(79). /* O */</p>
<p>vowel(85). /* U */</p>
<p>vowel(97). /* a */</p>
<p>vowel(101). /* e */</p>
<p>vowel(105). /* i */</p>
<p>vowel(111). /* o */</p>
<p>vowel(117). /* u */</p>
<p><strong>?- go(Vowels).</strong></p>
<p><strong>: In the beginning was the word*</strong></p>
<p><strong>Vowels = 8</strong></p>
<p><strong>?- go(Vowels).</strong></p>
<p><strong>: pqrst*</strong></p>
<p><strong>Vowels = 0</strong></p>
<p><strong> </strong></p>
<p><strong>Input and Output Using Files</strong></p>
<p>Prolog takes all input from the <em>current input stream </em>and writes all output to the <em>current output  stream</em>. By default both of these are the stream named <em>user</em>, denoting the user&#8217;s <em>terminal</em>, i.e. keyboard for input and screen for output.</p>
<h3><strong>File Output: Changing the Current Output Stream</strong></h3>
<p>The current output stream can be changed using the <strong>tell/1 </strong>predicate. This takes a single argument,  which is an atom or variable representing a file name, e.g. <strong>tell(&#8216;outfile.txt&#8217;)</strong>.</p>
<h3>Output to a File</h3>
<p>Although the above definition of <strong>tell </strong>states that &#8216;any existing file with the same name is deleted&#8217;, there is another possibility, which is important for some applications, namely that the file is not deleted and any output is placed after the end of the existing contents of the file. Both the &#8216;overwrite&#8217; and the &#8216;append&#8217; options are likely to be available in any practical implementation of Prolog but may involve using a different predicate (e.g. <strong>open</strong>) instead of or as well as <strong>tell</strong>.</p>
<h3><strong>File Input: Changing the Current Input Stream</strong></h3>
<p>The current input stream can be changed using the <strong>see/1 </strong>predicate. This takes a single argument, which is an atom or variable representing a file name, e.g. <strong>see(&#8216;myfile.txt&#8217;)</strong>.</p>
<h3>Reading from Files: End of File</h3>
<p>If the end of file is encountered while evaluating the goal <strong>get(X) </strong>or <strong>get0(X)</strong>, variable <strong>X </strong>will be bound to a &#8216;special&#8217; numerical value. As ASCII values must be in the range 0 to 255 inclusive, this will typically be -1, but may vary from one implementation of Prolog to another.</p>
<h3>Reading from Files: End of Record</h3>
<p>Typically the end of a line of input at the user&#8217;s terminal will be indicated by the character with ASCII value 13. The end of a record in a file will generally be indicated by two ASCII values: 13 followed by 10.</p>
<p>readline:-get0(X),process(X).</p>
<p>process(13).</p>
<p>process(X):-X=\=13,put(X),nl,readline.</p>
<p><strong>?- readline.</strong></p>
<p><strong>: Prolog test</strong></p>
<p><strong>Pr</strong></p>
<p><strong>ol</strong></p>
<p><strong>og</strong></p>
<p><strong>t</strong></p>
<p><strong>est</strong></p>
<p><strong>yes</strong></p>
<h3>Using Files: Examples</h3>
<p>Example 1</p>
<p>Adapt the final program given in Section 5.6 only the first line of the previous program needs to be changed, to:</p>
<p>go(Vowels):-see(&#8216;myfile.txt&#8217;),count(0,Vowels),seen.</p>
<p>Example 2</p>
<p>Define a predicate <strong>readterms </strong>to read the first four terms from a specified file and output them to another specified file, one per line. A suitable definition is given below.</p>
<p>readterms(Infile,Outfile):-</p>
<p>see(Infile),tell(Outfile),</p>
<p>read(T1),write(T1),nl,read(T2),write(T2),nl,</p>
<p>read(T3),write(T3),nl,read(T4),write(T4),nl,</p>
<p>seen,told.</p>
<p>Assuming the contents of file <em>textfile.txt </em>are the three lines:</p>
<p>&#8216;first term&#8217;. &#8216;second term&#8217;.</p>
<p>&#8216;third term&#8217;.</p>
<p>&#8216;fourth term&#8217;. &#8216;fifth term&#8217;.</p>
<p>using <strong>readterms </strong>gives the following brief output:</p>
<p><strong>?- readterms(&#8216;textfile.txt&#8217;,'outfile.txt&#8217;).</strong></p>
<p><strong>Yes</strong></p>
<p>and creates a file with four lines of text</p>
<p>first term</p>
<p>second term</p>
<p>third term</p>
<p>fourth term</p>
<p>Although the definition of <strong>readterms </strong>above is correct as far as it goes, the final two terms (<strong>seen </strong>and <strong>told</strong>) will cause the current input and output streams to be set to <em>user</em>. This could cause problems if <strong>readterms </strong>were used as a subgoal in a larger program where the current input and output streams were not necessarily both <em>user </em>when it was called. Using these conventions, the revised definition of <strong>readterms </strong>is as follows:</p>
<p>readterms(Infile,Output):-</p>
<p>seeing(S),see(Infile),telling(T),tell(Outfile),</p>
<p>read(T1),write(T1),nl,read(T2),write(T2),nl,</p>
<p>read(T3),write(T3),nl,read(T4),write(T4),nl,</p>
<p>seen,see(S),told,tell(T).</p>
<p>Example 3</p>
<p>Define a predicate <strong>copychars </strong>to copy characters input (as a single line) at the user&#8217;s terminal to a specified file, until the character <strong>! </strong>is entered (this character should not be copied). The rest of the task is left to <strong>copy_characters</strong>, which is defined recursively in a similar way to <strong>readin </strong>in the first example in Section 5.6.</p>
<p>copychars(Outfile):- telling(T),tell(Outfile),</p>
<p>copy_characters,told,tell(T).</p>
<p>copy_characters:-get0(N),process(N).</p>
<p>/* 33 is ASCII value of character ! */</p>
<p>process(33).</p>
<p>process(N):-N=\=33,put(N),copy_characters.</p>
<p>Using <strong>copychars </strong>as follows</p>
<p><strong>?- copychars(&#8216;myfile.txt&#8217;).</strong></p>
<p><strong>: abxyz!</strong></p>
<p><strong>yes</strong></p>
<p>will place the characters <em>abxyz </em>in file <em>myfile.txt</em>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=98&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/11/25/98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>
	</item>
		<item>
		<title>Expert System Design for Events Guide</title>
		<link>http://mathmaniacs.wordpress.com/2009/11/24/expert-system-design-for-cellular-communication/</link>
		<comments>http://mathmaniacs.wordpress.com/2009/11/24/expert-system-design-for-cellular-communication/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 15:49:52 +0000</pubDate>
		<dc:creator>mathmaniacs</dc:creator>
				<category><![CDATA[Expert System Design]]></category>

		<guid isPermaLink="false">http://mathmaniacs.wordpress.com/?p=88</guid>
		<description><![CDATA[Application of Expert System. Background of the idea : A program that helps to show some events that has been occured, is happening and will happend in the future in different locations. Detail explanation of the idea : First we should collect some events from the past, now and future and then write them in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=88&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Application of Expert System.</p>
<p>Background of the idea :</p>
<p>A program that helps to show some events that has been occured, is happening and will happend in the future in different locations.</p>
<p>Detail explanation of the idea :</p>
<p>First we should collect some events from the past, now and future and then write them in the facts of prolog. Example :</p>
<p>Events :</p>
<p>1. Computer Exhibition &#8220;Scomdex&#8221; in Surabaya Expo at November 2nd-7th 2009.</p>
<p>2. Surabaya Sale, discounts in some malls in  Surabaya including Tunjungan Plaza for remembering the anniversary of Surabaya City at November 9th-21st 2009.</p>
<p>3. Surabaya Book Fair in Surabaya Expo at November 16th-29th 2009</p>
<p>4. Kindergarten and Elementary Carnaval in Tugu Pahlawan at  November 29th 2009.</p>
<p>5. Music Concert in Tunjungan Plaza for teenagers at December 1st-3rd 2009.</p>
<p>6. Food Festival everyday in Pakuwon City in east Surabaya.</p>
<p>7. Music By Request, online in some Radio Stations in Surabaya everyday at 07.00 PM.</p>
<p>8. Education Expo, giving valuable experience for student in Surabaya Expo at December 7th-12nd.</p>
<p>9. Surabaya Real Estate Property Exhibition for executives in Pakuwon City at December 1st-31st 2009.</p>
<p>from the facts above then we create the rules that showing</p>
<p>1. How expensive the food available on each events;</p>
<p>2. How far between each event locations.</p>
<p>From the facts and rules created above we can make syntax to determine such as :</p>
<p>1. find some events at specific times, dates and locations.</p>
<p>2. find the cheaper prise of the food available in each events.</p>
<p>3. list all events with some classifications such as only for adults, family, teenagers, kids etc.</p>
<p>4. list the events that near with specific locations.</p>
<p>Benefit :</p>
<p>From the program we can make easy to get some information about events that have been occured, is happening and will happend in Surabaya area.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mathmaniacs.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mathmaniacs.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mathmaniacs.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mathmaniacs.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mathmaniacs.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mathmaniacs.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mathmaniacs.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mathmaniacs.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mathmaniacs.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mathmaniacs.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mathmaniacs.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mathmaniacs.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mathmaniacs.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mathmaniacs.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mathmaniacs.wordpress.com&amp;blog=9741099&amp;post=88&amp;subd=mathmaniacs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mathmaniacs.wordpress.com/2009/11/24/expert-system-design-for-cellular-communication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3edac2092c9a1dd36c9f5e220cbf8f49?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mathmaniacs</media:title>
		</media:content>
	</item>
	</channel>
</rss>
