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

<channel>
	<title>Saulo Silva&#039;s Blog</title>
	<atom:link href="http://saulosilva.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://saulosilva.com</link>
	<description>On technology, programming, et cetera.</description>
	<lastBuildDate>Wed, 23 Nov 2011 22:43:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Oracle rebrands Java, breaks Eclipse</title>
		<link>http://saulosilva.com/2010/07/oracle-rebrands-java-breaks-eclipse/</link>
		<comments>http://saulosilva.com/2010/07/oracle-rebrands-java-breaks-eclipse/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 14:02:54 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://saulosilva.com/?p=838</guid>
		<description><![CDATA[The last release of  Java—version 1.6.0 update 21—was rebranded as being made by “Oracle” instead of “Sun Microsystems, Inc”. The problem is that Eclipse uses that value to decide on whether or not to pass a specific argument to the Virtual Machine. This change affects Eclipse versions 3.3 (released in 2007) to 3.6 (released in 2010), [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-848 alignleft" title="Eclipse and Oracle" src="http://saulosilva.com/wp-content/uploads/2010/07/eclipse_oracle.png" alt="" width="144" height="99" />The last release of  Java—version 1.6.0 update 21—was rebranded as being made by “Oracle” instead of “Sun Microsystems, Inc”.</p>
<p>The problem is that <a href="https://bugs.eclipse.org/bugs/attachment.cgi?id=174008&amp;action=diff">Eclipse uses that value</a> to decide on whether or not to pass a specific argument to the Virtual Machine.</p>
<p>This change affects Eclipse versions 3.3 (released in 2007) to 3.6 (released in 2010), causing the IDE to hang consistently, without any error messages.</p>
<p>The guys at Eclipse.org have posted <a href="http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#Oracle.2FSun_VM_1.6.0_21_on_Windows">three workarounds</a> for this issue. (Since I’m using Helios, I opted for no. 3.)</p>
<p>Here is the bug  on the <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6969236">Oracle</a> and on the <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=319514">Eclipse</a> side.</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2010/07/oracle-rebrands-java-breaks-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to load a properties file from a servlet</title>
		<link>http://saulosilva.com/2009/06/how-to-load-a-properties-files-from-a-servlet/</link>
		<comments>http://saulosilva.com/2009/06/how-to-load-a-properties-files-from-a-servlet/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 14:48:30 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=433</guid>
		<description><![CDATA[I wanted to read a properties file from a servlet without using a hard-coded, absolute path. I tried to search on the web for a portable solution, but I couldn&#8217;t find anything. Here is the trick: use ServletContext.getRealPath(String). For instance, a file called &#8220;config.properties&#8221; located in &#8220;WEB-INF&#8221;, can be loaded like this:]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-462" title="config.properties" src="http://saulosilva.com/wp-content/uploads/2009/07/config.properties.png" alt="config.properties" /></p>
<p>I wanted to read a properties file from a servlet without using a hard-coded, absolute path. I tried to <a href="http://www.google.ca/search?q=load+properties+file+from+servlet">search on the web</a> for a portable solution, but I couldn&#8217;t find anything.</p>
<p>Here is the trick: use <code><a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)">ServletContext.getRealPath(String)</a></code>. For instance, a file called &#8220;config.properties&#8221; located in &#8220;WEB-INF&#8221;, can be loaded like this:</p>
<pre class="brush: java; title: ; notranslate">
public void init(ServletConfig config) throws ServletException {
	String pathToPropertiesFile =
		config.getServletContext().getRealPath(&quot;&quot;)
		+ &quot;/WEB-INF/config.properties&quot;;
	Properties properties = new Properties();
	properties.load(new FileInputStream(pathToPropertiesFile));
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2009/06/how-to-load-a-properties-files-from-a-servlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aspect-oriented programming with AspectJ</title>
		<link>http://saulosilva.com/2009/03/aspect-oriented-programming-with-aspectj/</link>
		<comments>http://saulosilva.com/2009/03/aspect-oriented-programming-with-aspectj/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 03:35:47 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[aspectj]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=276</guid>
		<description><![CDATA[In one of the courses I took this session I was introduced to aspect-oriented programming. For those who are not familiar with it, an aspect can be used to implement a concern that is crosscutting among different components. There are a few such concerns that are commonly affected by crosscutting, namely: authentication, persistence, logging and [...]]]></description>
			<content:encoded><![CDATA[<p>In one of the courses I took this session I was introduced to aspect-oriented programming. For those who are not familiar with it, an aspect can be used to implement a concern that is crosscutting among different components.</p>
<p>There are a few such concerns that are commonly affected by crosscutting, namely: authentication, persistence, logging and contract checking.</p>
<p>It is argued that with object-oriented programming, even after proper refactoring, it is not always possible to map a requirement to a single component. When a requirement is implemented by more than one component, scattering occurs. <acronym title="Aspect-oriented programming">AOP</acronym> allows you to localize the scattered requirement into an aspect.</p>
<p>AspectJ is an extension to the Java language that adds support to <acronym title="Aspect-oriented programming">AOP</acronym>. An aspect in AspectJ is composed of <em>pointcuts</em> and <em>advices</em>. A pointcut defines the condition that needs to be met in order for the logic in an advice to be executed. A pointcut could be, for instance, the execution of a method in a particular class.</p>
<h3>How AspectJ can be useful</h3>
<p>Let&#8217;s look at an example. Say we want to log when <a title="A horse drinking water." href="http://www.flickr.com/photos/architekt2/185791912/">horses drink water</a> and when <a title="A cow eating grass." href="http://www.flickr.com/photos/dizzo/2168240431/">cows eat grass</a>. Assume we have a class <code>Logger</code> with a static method <code>log()</code>. Here&#8217;s what the implementation could look like:</p>
<pre class="brush: java; title: ; notranslate">public class Horse {
	private int consumedWaterInLitres;

	public void drink() {
		consumedWaterInLitres++;
		Logger.log(&quot;A horse is drinking water.&quot;);
	}
}

public class Cow {
	private int consumedGrassInGrams;

	public void eat() {
		consumedGrassInGrams++;
		Logger.log(&quot;A cow is eating grass.&quot;);
	}
}</pre>
<p>The argument is that the concern of logging is now crosscut among the Horse and Cow components. In addition, it can be said that <code>Horse.drink()</code> and <code>Cow.eat()</code> are responsible for more core logic (eating and drinking) than they should have been. Let&#8217;s try to fix this problem with an aspect:</p>
<pre class="brush: java; title: ; notranslate">public aspect Logging {
	pointcut logHorseDrinking() : call(public void Horse.drink());
	pointcut logCowEating() : call(public void Cow.eat());

	void after() : logHorseDrinking() {
		Logger.log(&quot;A horse is drinking water.&quot;);
	}

	void after() : logCowEating() {
		Logger.log(&quot;A cow is eating grass.&quot;);
	}
}</pre>
<p>Here we defined two pointcuts that capture calls to <code>Horse.drink()</code> and to <code>Cow.eat()</code>. We&#8217;ve attached these pointcuts to two advices that will run after these methods are executed. With the Logging aspect in place, we can now remove all calls to <code>Logger.log()</code> from <code>Horse</code> and <code>Cow</code>. Isn&#8217;t that great?</p>
<h3>How AspectJ can be dangerous</h3>
<p><img class="size-full wp-image-330 alignright" title="Dog Class Diagram" src="http://saulosilva.com/wp-content/uploads/2009/03/dog_class_diagram.png" alt="Dog before DogAspect" width="86" height="46" /></p>
<p>Aspects can also add state, behaviour and inheritance to a component. Privileged aspects have access to all features in a system—including private ones. Does that raise a red flag? Let&#8217;s look at the class <code>Dog</code> below.</p>
<pre class="brush: java; title: ; notranslate">public class Dog {
}</pre>
<p>It has no features—no attributes nor methods—and doesn&#8217;t extend from any class, right? Wrong:</p>
<pre class="brush: java; title: ; notranslate">public aspect DogAspect {
	declare parents: Dog extends Animal;
	private String Dog.ownersName = &quot;Bobert&quot;;

	public String Dog.getOwnwersName() {
		return ownersName;
	}
}</pre>
<p><img class="size-full wp-image-353 alignright" title="Class Dog after DogAspect" src="http://saulosilva.com/wp-content/uploads/2009/03/dog_after_dogaspect.png" alt="Dog after DogAspect" width="146" height="136" /></p>
<p>The aspect above has completely changed the class <code>Dog</code>. It has made it an <code>Animal</code>, it has added an attribute <em>ownersName</em> and a getter for it. The worst part is that <code>Dog</code> is completely oblivious to the aspect—it will never know about it. In fact, unless you as a developer look at all aspects on the system, you will never know about it either.</p>
<p>That is not completely true because some <acronym title="Integrated development environment">IDE</acronym>s will provide a visual clue whenever a class is affected by an aspect. The <a href="http://www.eclipse.org/ajdt/">AspectJ Developement Tools</a> add-on for <a href="http://eclipse.org/">Eclipse</a> (a great <acronym title="Integrated development environment">IDE</acronym> by the way) is supposed to show a marker on the editor margin whenever a component is being advised by an aspect. I have the latest version installed (ADJT 1.6.4) but for some reason the marker is not showing up, unfortunately.</p>
<p>There are also other issues one might encounter when using AspectJ. It is not an easy task to document the impact aspects have on a system—<acronym title="Unified Modeling Language">UML</acronym> has no support for aspects at this moment, and how are you going to show that on a sequence diagram? Also, the debugging and tracing of execution of a class that is being advised by an aspect can get pretty tricky.</p>
<h3>In conclusion</h3>
<p>I believe that the application of <acronym title="Aspect-oriented programming">AOP</acronym> could indeed improve the quality of a system through the localization of crosscutting concerns. However, its Java implementation—AspectJ—provides a level of control that is too risky to be used in industrial medium- to large-scale projects. Its supporting technologies and documenting tools have not yet reached the desired maturity level.</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2009/03/aspect-oriented-programming-with-aspectj/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Should we use foreign-key constraints when persisting Domain Models?</title>
		<link>http://saulosilva.com/2009/02/domain-model-persistence-and-foreign-key-constraints/</link>
		<comments>http://saulosilva.com/2009/02/domain-model-persistence-and-foreign-key-constraints/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 19:53:25 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=253</guid>
		<description><![CDATA[Since last summer I&#8217;ve been working with three other Software Engineering undergraduates on a web enterprise application that will eventually replace a legacy ERP system. We used patterns from Martin Fowler&#8217;s Patterns of Enterprise Application Architecture (a great book, by the way), and the well-known three-layered architecture. One day we had a discussion related to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://saulosilva.com/wp-content/uploads/2009/02/mediawiki-database-schema.png"><img class="size-thumbnail wp-image-264 alignleft" title="The Mediawiki database schema" src="http://saulosilva.com/wp-content/uploads/2009/02/mediawiki-database-schema-150x150.png" alt="Mediawiki Database Schema" width="150" height="150" /></a></p>
<p>Since last summer I&#8217;ve been working with three other Software Engineering undergraduates on a web enterprise application that will eventually replace a legacy <acronym title="Enterprise Resource Planning">ERP</acronym> system. We used patterns from Martin Fowler&#8217;s <a href="http://martinfowler.com/books.html"><em>Patterns of Enterprise Application Architecture</em></a> (a great book, by the way), and the well-known three-layered architecture.</p>
<p>One day we had a discussion related to the persistence of <a title="The Domain Model software design pattern." href="http://martinfowler.com/eaaCatalog/domainModel.html">Domain Model</a>s and whether we should enforce foreign-key constraints at the database level. My first reaction was that the very use of a relational database implied the enforcement of such constraints, but some of my colleagues argued that the database should be seen as nothing but a persistence mechanism and therefore we should avoid placing any business logic in it. We ended up by not using foreign-key constraints.</p>
<p>Would you have done otherwise? I would like to hear what other software engineers/developers have to say about this.</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2009/02/domain-model-persistence-and-foreign-key-constraints/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mighty Putty</title>
		<link>http://saulosilva.com/2009/01/mighty-putty/</link>
		<comments>http://saulosilva.com/2009/01/mighty-putty/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 16:29:31 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Humour]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=234</guid>
		<description><![CDATA[Hey guys, sorry for the lack of updates. My last semester has been a little bit hectic, but in three months I&#8217;ll be a (Junior) Software Engineer! :) Here&#8217;s a little video I just stumbled upon on reddit.]]></description>
			<content:encoded><![CDATA[<p>Hey guys, sorry for the lack of updates. My last semester has been a little bit hectic, but in three months I&#8217;ll be a (Junior) Software Engineer! :)</p>
<p>Here&#8217;s a little video I just stumbled upon on reddit.</p>
<p><object width="500" height="400"><param name="movie" value="http://www.youtube.com/v/r_4a4O7kXQo?fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/r_4a4O7kXQo?fs=1" type="application/x-shockwave-flash" width="500" height="400" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2009/01/mighty-putty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Chrome, a new web browser</title>
		<link>http://saulosilva.com/2008/09/google-chrome-a-new-web-browser/</link>
		<comments>http://saulosilva.com/2008/09/google-chrome-a-new-web-browser/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 23:11:46 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[web browser]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=170</guid>
		<description><![CDATA[Google confirmed tomorrow&#8217;s launch of Google Chrome beta, a new open source web browser that borrows the rendering engine from Apple&#8217;s WebKit and components from Mozilla Firefox. An important design aspect behind Google Chrome is that each tab will be assigned an entire process instead of a thread within a process. This means that if [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-179 alignleft" title="Google Chrome logo" src="http://saulosilva.com/wp-content/uploads/2008/09/google_chrome_logo.jpg" alt="" width="130" height="150" /><a href="http://googleblog.blogspot.com/2008/09/fresh-take-on-browser.html">Google confirmed</a> tomorrow&#8217;s launch of Google Chrome beta, a new open source web browser that borrows the rendering engine from Apple&#8217;s WebKit and components from Mozilla Firefox.</p>
<p>An important design aspect behind Google Chrome is that each tab will be assigned an entire process instead of a thread within a process. This means that if a particular website causes the page to hang, only its tab will have to be closed. In addition, a task manager will allow the user to see which page, plug-in or web application is consuming system resources, a feature available in all modern <acronym title="Operating System">OS</acronym>s.</p>
<p>Google has published a <a href="http://www.google.com/googlebooks/chrome/">comic</a> that explains in 38 pages their web browser project.</p>
<p>How will this affect the battle for market share between existing web browsers? Will Google Chrome be adopted by Firefox or <acronym title="Internet Explorer">IE</acronym> users?</p>
<p><a href="http://saulosilva.com/wp-content/uploads/2008/09/google_chrome_comic_page_38.png"><img class="size-thumbnail wp-image-177 alignnone" title="Google Chrome Comic page 38" src="http://saulosilva.com/wp-content/uploads/2008/09/google_chrome_comic_page_38-150x150.png" alt="Google Chrome Comic page 38" width="150" height="150" /></a> <a href="http://saulosilva.com/wp-content/uploads/2008/09/google_chrome_screenshot.jpg"><img class="size-thumbnail wp-image-186 alignnone" title="A screenshot of Google Chrome" src="http://saulosilva.com/wp-content/uploads/2008/09/google_chrome_screenshot-150x150.jpg" alt="A screenshot Google Chrome" width="150" height="150" /></a></p>
<p><strong>Update 1</strong>: added a screenshot (found at <a href="http://www.techcrunch.com/2008/09/01/first-public-screen-captures-of-google-chrome/">TechCrunch</a>).<br />
<strong>Update 2:</strong> <a title="Google Chrome" href="http://www.google.com/chrome/">The Google Chrome webpage is up</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2008/09/google-chrome-a-new-web-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Goodbye PensCMS, hello WordPress!</title>
		<link>http://saulosilva.com/2008/08/goodbye-penscms-hello-wordpress/</link>
		<comments>http://saulosilva.com/2008/08/goodbye-penscms-hello-wordpress/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 15:54:20 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Site updates]]></category>

		<guid isPermaLink="false">http://pensador.org/?p=119</guid>
		<description><![CDATA[After realizing that I would never match the power of hundreds of developers behind WordPress&#8217; success, I decided to ditch my own custom, ad hoc content management system. PensCMS had been around for eight years, and I had just successfully solved the spam problem with reCAPTCHA (I know, I should have thought about that before!). [...]]]></description>
			<content:encoded><![CDATA[<p>After realizing that I would never match the power of hundreds of developers behind WordPress&#8217; success, I decided to ditch my own custom, <em>ad hoc</em> content management system. PensCMS had been around for eight years, and I had just successfully solved the spam problem with <a href="http://recaptcha.net/">reCAPTCHA</a> (I know, I should have thought about that before!). The other thing that really bothered me with my own blogging software is that in order to add images to a post, I had to manually resize, upload via FTP and paste the code for them, which was a painful process to say the least.</p>
<p>I prefer to always include at least an image with my posts, so this was a big issue for me.  As I thought about a solution, I had a sudden spark of humbleness: maybe it&#8217;s OK to use other people&#8217;s work instead of doing it all myself from the ground up.</p>
<p><img class="size-full wp-image-135 alignleft" title="Wordpress" src="http://saulosilva.com/wp-content/uploads/2008/08/wp-20-square-button-trans.gif" alt="Wordpress" /></p>
<p>After some research, I narrowed down to two options: <a href="http://wordpress.org">WordPress</a> and <a href="http://blogger.com">Blogger</a>. The reason why I chose the former is that I wanted to transfer all my posts and comments from my old blog. The easiest way of doing so (although a bit long and tedious) was to manually add them to the database. The other option was to convert all posts and comments to XML—which I did—but I was unable to import into Blogger. Besides, there is no way of creating the <a href="/about/">about</a> and <a href="/quotes/">quotes</a> pages on the Google-maintained blogging system.</p>
<p>I spent the whole day yesterday moving posts and comments, customizing the <a href="http://ifelse.co.uk/simpla">Simpla</a> theme and installing plug-ins. I left behind some posts that were either too old or too silly—I did keep the ones that were chronologically interesting such as the post on how <a href="http://pensador.org/2003/10/17/mozilla-firebird-a-great-ie-alternative/">Firebird (now &#8220;Firefox&#8221;) was good alternative to IE</a>.</p>
<p>I am happy with the results and I will try to write more often now that I don&#8217;t have to open Paint.NET and FileZilla in order to post an article!</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2008/08/goodbye-penscms-hello-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Applying the Chinese Remainder Theorem</title>
		<link>http://saulosilva.com/2007/10/applying-the-chinese-remainder-theorem/</link>
		<comments>http://saulosilva.com/2007/10/applying-the-chinese-remainder-theorem/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 13:17:59 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[How-Tos]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[mathematics]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=1</guid>
		<description><![CDATA[In public-key Cryptography, especially with the RSA algorithm, the Chinese Remainder Theorem is often used. Say you have a system of simultaneous congruences as follows x a1 mod m1 x a3 mod m2 x ak mod mk , where m1, m2, &#8230;, mk are coprime, i.e. gcd(m1, m2, &#8230;, mk) = 1. How can we [...]]]></description>
			<content:encoded><![CDATA[<p>In public-key Cryptography, especially with the <a href="http://en.wikipedia.org/wiki/RSA">RSA algorithm</a>, the Chinese Remainder Theorem is often used. Say you have a system of simultaneous congruences as follows</p>
<p>x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" /> a<sub>1</sub> mod m<sub>1</sub><br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" /> a<sub>3</sub> mod m<sub>2</sub><br />
<img class="size-full wp-image-106 noborder alignnone" title="Vertical Ellipsis" src="http://saulosilva.com/wp-content/uploads/2008/08/vertical_ellipsis.png" alt="" width="5" height="20" /><br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" /> a<sub>k</sub> mod m<sub>k</sub> ,</p>
<p>where m<sub>1</sub>, m<sub>2</sub>, &#8230;, m<sub>k</sub> are coprime, i.e. <acronym title="Greatest common divisor">gcd</acronym>(m<sub>1</sub>, m<sub>2</sub>, &#8230;, m<sub>k</sub>) = 1.   How can we solve for x? The solution is quite straight forward, but could involve a   fair amount of calculations. I find that breaking down the method into smaller steps   makes it easier to find and fix mistakes. By the Chinese   Remainder Theorem, the solution to that system of equations is</p>
<p style="text-align: center;">x =   (a<sub>1</sub>M<sub>1</sub>y<sub>1</sub> + a<sub>2</sub>M<sub>2</sub>y<sub>2</sub> + &#8230; + a<sub>k</sub>M<sub>k</sub>y<sub>k</sub>) mod M ,</p>
<p>where M<sub>i</sub> is the product of all   m&#8217;s except for m<sub>i</sub></p>
<p style="text-align: center;"><img class="size-full wp-image-107 noborder alignnone" title="How to compute M sub i" src="http://saulosilva.com/wp-content/uploads/2008/08/mi.png" alt="" width="77" height="54" />,</p>
<p>y<sub>i</sub> is the multiplicative inverse of M<sub>i</sub> modulo m<sub>i</sub></p>
<p style="text-align: center;">y<sub>i</sub> <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> M<sub>i</sub><sup>-1</sup> mod m<sub>i</sub> ,</p>
<p style="text-align: center;">and M = m<sub>1</sub> * m<sub>2</sub> * &#8230; * m<sub>k</sub> .</p>
<p>Let us try a numeric example. Here is a system of simultaneous congruences:</p>
<p style="text-align: center;">x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 12 mod 25<br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 9 mod 26<br />
x <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 23 mod 27</p>
<p>We start by calculating M<sub>1</sub> and y<sub>1</sub>:</p>
<p style="text-align: center;">M<sub>1</sub> = m<sub>2</sub> * m<sub>3</sub> = 26 * 27 = 702</p>
<p style="text-align: center;">y<sub>1</sub> = M<sub>1</sub><sup>-1</sup> mod m<sub>1</sub> = 702<sup>-1</sup> mod 25 .</p>
<p>We apply the <a href="http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm">Extended Euclidean Algorithm</a> to find the multiplicative inverse of 702 relative to 25:</p>
<p>702 = 28 * 25 + 2  → 2 = 702 – 28 * 25<br />
25   = 12 * 2 + 1      → 1 = 25 – 12 * <span style="text-decoration: underline;">2</span><br />
= 25 – 12 * (702 – 28 * 25)<br />
= 337 * 25 – 12 * 702</p>
<p>Then y<sub>1</sub> = 702<sup>-1</sup> mod 25 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> -12 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 13.</p>
<p>The same calculations can be carried on to find M<sub>2</sub> = 675, y<sub>2</sub> = 25, M<sub>3</sub> = 650 and y<sub>3</sub> = 14. Now it is just a matter of plugging in the values into the equation:</p>
<p>x = (a<sub>1</sub>M<sub>1</sub>y<sub>1</sub> + a<sub>2</sub>M<sub>2</sub>y<sub>2</sub> + a<sub>3</sub>M<sub>3</sub>y<sub>3</sub>) mod  M<br />
= (12*702*13 + 9*675*25 + 23*650*14) mod 17550 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 470687 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 14387</p>
<p>To verify our answer we can plug that number back into the system:</p>
<p style="text-align: center;">470687 mod 25 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 12<br />
470687 mod 26 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 9<br />
470687 mod 27 <img class="alignnone size-full wp-image-103 noborder" title="Congruence" src="http://saulosilva.com/wp-content/uploads/2008/08/congruence.png" alt="" width="11" height="13" /> 23</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2007/10/applying-the-chinese-remainder-theorem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Another kidney stone bites the dust</title>
		<link>http://saulosilva.com/2007/08/another-kidney-stone-bites-the-dust/</link>
		<comments>http://saulosilva.com/2007/08/another-kidney-stone-bites-the-dust/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 15:40:42 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=15</guid>
		<description><![CDATA[This Monday I had yet another renal calculus crisis—the second one in less than 12 months. There was I, in the emergency section of the local hospital contorting in pain from 18:30 to 22:30. By 23:00 the stone had moved from my ureter to my bladder, which reduced the pain, and by the next day [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-145" title="Stonehenge" src="http://saulosilva.com/wp-content/uploads/2008/08/480px-stonehenge.jpg" alt="" width="480" height="328" /></p>
<p>This Monday I had yet another renal calculus crisis—the second one in less than 12 months. There was I, in the emergency section of the local hospital contorting in pain from 18:30 to 22:30. By 23:00 the stone had moved from my <a href="http://en.wikipedia.org/wiki/Ureter">ureter</a> to my bladder, which reduced the pain, and by the next day it finally got expelled from my system. After a blood test and an x-ray, the doctor said I had to drink more water and reduce the salt in my diet. I am considering taking <a href="http://sacredlotus.com/herbs/herb.cfm/hid/183">Herba Desmodii</a> capsules, a natural diuretic, which a co-worker said does wonders to kidney stones.</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2007/08/another-kidney-stone-bites-the-dust/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How games negatively affected my life</title>
		<link>http://saulosilva.com/2007/07/how-games-negatively-affected-my-life/</link>
		<comments>http://saulosilva.com/2007/07/how-games-negatively-affected-my-life/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 15:55:50 +0000</pubDate>
		<dc:creator>Saulo</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[addiction]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[World of Warcraft]]></category>

		<guid isPermaLink="false">http://pensador.org/wordpress/?p=19</guid>
		<description><![CDATA[A short but true story of someone who decided to quit World of Warcraft.]]></description>
			<content:encoded><![CDATA[<p><em>A short but true story of someone who decided to quit World of Warcraft.</em></p>
<p>In the afternoon of November 23 of 2004, after my last class of the day, I headed to a computer store where I had reserved a copy of <em>World of Warcraft Collector&#8217;s Edition</em>. Three years later, I  look back and I realize how I almost ruined my life with a computer game.</p>
<p>I am an undergraduate in Software Engineering. I feel kind of silly writing this, but I will share my true story with the intent of helping somebody who might be going through what I went through. I hope this will not bore you.</p>
<p>I was addicted to WoW during my first year of university. I seemed to be a pretty dedicated student; I did not miss any lectures and took detailed notes. However, my head would wander elsewhere—be it sketching my character, building her skills and planning the next quests. As an active member of a guild, I was the first to get a mount. Every day of my life led to the same—as soon as I got home, I would go straight to the computer and log in to WoW. My idea of having a good time was spending hours and hours in front of the screen completing quests, levelling up and earning gold at the auction house.</p>
<p>All was fun until I saw my first transcript:  A+, C+, C+, C, C-, D+, D, D-, D- and D-.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-738" title="grades-first-year" src="http://saulosilva.com/wp-content/uploads/2007/07/grades-first-year.png" alt="" /></p>
<p>With these results, I had a GPA of 1.96. In my institution, you need to keep it higher than 2.00, or else you get expelled. I decided to take a definite and concrete action. Not only did I uninstall WoW from my computer but also I completely eliminated games from my life. If I told you that I even removed the solitaire card game that comes with Windows, you would probably laugh, but I really wanted to stick with my resolution.</p>
<p>I also changed my studying habits. I stayed long hours at the university, reading lectures in advance, redoing exercises, rewriting notes—I pretty much lived at the library at that point. When I got my transcript I thought it was someone else&#8217;s: A, A, A, A-, B, B, B, B, B-, D+ and D-.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-739" title="grades-second-year" src="http://saulosilva.com/wp-content/uploads/2007/07/grades-second-year.png" alt="" /></p>
<p>I knew that if I could stay focused and stick to my study routine, I would do even better. I was not mistaken. Here is my transcript for the third year: A+, A, A, A-, A-, A-, B+ and B-. Nothing below a B-grade, and now I have a cumulative GPA of 3.02.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-738" title="grades-first-year" src="http://saulosilva.com/wp-content/uploads/2007/07/grades-third-year.png" alt="" width="449" height="267" /></p>
<p>That is only one side of my life that changed. Since I quit, I have met many interesting people, including a gorgeous and smart girl who is now my fiancée.<br />
Some will say that it was not the game that influenced me but it was I who had problems in the first place; that might have been the case. I agree that games do not ruin lives, people ruin lives; all I can say is that now I have more free time to spend with those that I love: my family and friends.</p>
]]></content:encoded>
			<wfw:commentRss>http://saulosilva.com/2007/07/how-games-negatively-affected-my-life/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
	</channel>
</rss>

