<?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>Math and More</title>
	<atom:link href="http://bloggingmath.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bloggingmath.wordpress.com</link>
	<description>Problem solving at its best</description>
	<lastBuildDate>Sat, 08 Jun 2013 00:32:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='bloggingmath.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Math and More</title>
		<link>http://bloggingmath.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://bloggingmath.wordpress.com/osd.xml" title="Math and More" />
	<atom:link rel='hub' href='http://bloggingmath.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Implementing the Closest Pair Algorithm in OpenCL and WebCL</title>
		<link>http://bloggingmath.wordpress.com/2013/03/11/implementing-the-closest-pair-algorithm-in-opencl-and-webcl/</link>
		<comments>http://bloggingmath.wordpress.com/2013/03/11/implementing-the-closest-pair-algorithm-in-opencl-and-webcl/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 05:42:57 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Computational Geometry]]></category>
		<category><![CDATA[OpenCL]]></category>
		<category><![CDATA[WebCL]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=854</guid>
		<description><![CDATA[I was looking for a fun geometry problem to solve and came across the closest pair of points problem. The problem statement is: Given a set of points, in 2D, compute the closest pair of points. The brute force algorithm &#8230; <a href="http://bloggingmath.wordpress.com/2013/03/11/implementing-the-closest-pair-algorithm-in-opencl-and-webcl/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=854&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I was looking for a fun geometry problem to solve and came across the closest pair of points problem. </p>
<p>The problem statement is:<br />
Given a set of points, in 2D, compute the closest pair of points. </p>
<p>The brute force algorithm takes <img src='http://s0.wp.com/latex.php?latex=O%28n%5E2%29&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='O(n^2)' title='O(n^2)' class='latex' /> time. There&#8217;s a better solution described at the Wikipedia page <a href="http://en.wikipedia.org/wiki/Closest_pair_of_points_problem">Closest pair of points problem</a>, which takes <img src='http://s0.wp.com/latex.php?latex=O%28n+%5Ccdot+%5Ctextrm%7Blog%7D%28n%29%29&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='O(n &#92;cdot &#92;textrm{log}(n))' title='O(n &#92;cdot &#92;textrm{log}(n))' class='latex' /> time.<br />
As far as I know, there aren&#8217;t any posted solutions using OpenCL to compute the closest pair. So I&#8217;ve implemented one, it&#8217;s posted at <a href="https://github.com/bjwbell/OpenCL-Examples/tree/master/closest-pair">closest-pair</a>.</p>
<p>There are a few challenges in adapting the algorithm for OpenCL. Namely, we can&#8217;t use recursion so we must convert the recursive algorithm to a procedural one. In this case it&#8217;s not to complicated because the structure of the solution is easily converted from the top-down recursive algorithm to a bottom-up parallel algorithm. There are some tricky issues when the number of points are not a power of 2. I&#8217;ve commented the code for those cases.</p>
<p>The second challenge is using WebCL. WebCL has an additional restriction that you can&#8217;t pass structures between Javascript and OpenCL kernels. Because of this I had to use dumb arrays of simple uint&#8217;s instead of using arrays of uint2, uint3, and uint4. This made the code more verbose. To help reduce the verbosity I added macros in the OpenCL ckStrips kernel. The WebCL version is posted at<br />
<a href="http://htmlpreview.github.com/?https://github.com/bjwbell/OpenCL-Examples/blob/master/closest-pair/example_closest_pair_ocl.html">closest_pair_ocl.html</a>.</p>
<p>I hope the solution is useful to someone. Enjoy reading the code, it requires careful thought.<br />
Check it out at <a href="https://github.com/bjwbell/OpenCL-Examples/tree/master/closest-pair">closest-pair</a> or view the WebCL one online at <a href="http://htmlpreview.github.com/?https://github.com/bjwbell/OpenCL-Examples/blob/master/closest-pair/example_closest_pair_ocl.html">closest_pair_ocl.html</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/854/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/854/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=854&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2013/03/11/implementing-the-closest-pair-algorithm-in-opencl-and-webcl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>
	</item>
		<item>
		<title>Enabling WebCL Highlighting in Emacs</title>
		<link>http://bloggingmath.wordpress.com/2013/03/10/enabling-webcl-highlighting-in-emacs/</link>
		<comments>http://bloggingmath.wordpress.com/2013/03/10/enabling-webcl-highlighting-in-emacs/#comments</comments>
		<pubDate>Sun, 10 Mar 2013 01:29:02 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[OpenCL]]></category>
		<category><![CDATA[WebCL]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=861</guid>
		<description><![CDATA[When editing WebCL OpenCL kernels in Emacs I like to have the OpenCL kernel code highlighted as C code. This is easy to achieve using the multi-mode.el package. The steps on Ubuntu (or any other modern Linux with Emacs 24) &#8230; <a href="http://bloggingmath.wordpress.com/2013/03/10/enabling-webcl-highlighting-in-emacs/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=861&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When editing WebCL OpenCL kernels in Emacs I like to have the OpenCL kernel code highlighted as C code. This is easy to achieve using the multi-mode.el package. </p>
<p>The steps on Ubuntu (or any other modern Linux with <b>Emacs 24</b>) are</p>
<ol>
<li> Enable the <a href="http://marmalade-repo.org/" rel="nofollow">http://marmalade-repo.org/</a> elpa package archive by adding the below to your .emacs file and restarting Emacs
<pre>    (require 'package)
    (add-to-list 'package-archives 
    '("marmalade" .
      "http://marmalade-repo.org/packages/"))
    (package-initialize)
</pre>
</li>
<li> Install multi-web-mode by using &#8220;M-x package-list-packages&#8221; and scrolling down to &#8220;multi-web-mode&#8221;.</li>
<li> Add the below to the bottom of your .emacs file and restart Emacs
<pre>
    (require 'multi-web-mode)
    (setq mweb-default-major-mode 'html-mode)
    (setq mweb-tags '((php-mode "&lt;\\?php\\|&lt;\\? \\|")
                      (js-mode "]*&gt;" "")
                      (css-mode "]*&gt;" "")
	              (c-mode "]* +type=\"text/x-opencl\"[^&gt;]*&gt;" "")))
    (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
    (multi-web-global-mode 1)
</pre>
<p>   The important part is the &#8220;c-mode&#8221; section that will enable C highlighting for OpenCL kernels in html files.
</li>
<li> Start coding! </li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/861/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/861/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=861&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2013/03/10/enabling-webcl-highlighting-in-emacs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>
	</item>
		<item>
		<title>Computing the Smallest Enclosing Disk</title>
		<link>http://bloggingmath.wordpress.com/2012/10/06/computing-the-smallest-enclosing-disk/</link>
		<comments>http://bloggingmath.wordpress.com/2012/10/06/computing-the-smallest-enclosing-disk/#comments</comments>
		<pubDate>Sat, 06 Oct 2012 12:28:42 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Computational Geometry]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[enclosing disk]]></category>
		<category><![CDATA[geomety]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=807</guid>
		<description><![CDATA[I recently read in chapter 4 of Computational Geometry by de Berg et al. the problem of computing the smallest enclosing disk for a set of points. I&#8217;ve shamelessly stolen the algorithm from there and done a simple conversion to &#8230; <a href="http://bloggingmath.wordpress.com/2012/10/06/computing-the-smallest-enclosing-disk/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=807&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I recently read in chapter 4 of <a href="http://www.amazon.com/Computational-Geometry-Applications-Mark-Berg/dp/3540779736" title="Computational Geometry Algorithms and Applications">Computational Geometry</a> by de Berg et al. the problem of computing the smallest enclosing disk for a set of points.</p>
<p>I&#8217;ve shamelessly stolen the algorithm from there and done a simple conversion to Javascript. </p>
<p>The code is under the <a href="https://github.com/bjwbell/canvas-geolib" title="canvas-geolib">canvas-geolib</a> GitHub repository in the geometry.js file, there&#8217;s also an example @ <a href="http://cloud.github.com/downloads/bjwbell/canvas-geolib/enclosingdisk.html">enclosingdisk.html</a>. The example initially consists of three points and the smallest disk enclosing them. Click anywhere on the canvas and a new point will be added and the disk redrawn.</p>
<p>I don&#8217;t want to go over the general algorithm but I do want explain computing the unique disk with three points given for its boundary. In <a href="https://github.com/bjwbell/canvas-geolib/blob/master/geometry.js">geometry.js</a> the function &#8220;enclosingDisk3Points&#8221; takes three points and returns the unique disk that has those points on its boundary.</p>
<p>The below figure shows the two defining characteristics of the disk, which are (1) the disk center is centered at (x,y) and (2) the distance from the center to all three points (p0, p1, &amp; p3) is equal i.e. the distance from the center to all three points is d.</p>
<p><img src="http://bloggingmath.files.wordpress.com/2012/10/center-point2.png?w=908" alt="center point" /></p>
<p>From this computing (x,y) and d is simple. For simplicity we assume <img src='http://s0.wp.com/latex.php?latex=p_0+%3D+%280%2C+0%29&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='p_0 = (0, 0)' title='p_0 = (0, 0)' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=p_1+%3D+%280%2C+%7Bp_y%7D%29&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='p_1 = (0, {p_y})' title='p_1 = (0, {p_y})' class='latex' />, also we let <img src='http://s0.wp.com/latex.php?latex=p_2+%3D+%28%7Bq%7D_x%2C+%7Bq%7D_y%29&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='p_2 = ({q}_x, {q}_y)' title='p_2 = ({q}_x, {q}_y)' class='latex' />.</p>
<p>The set of equations to solve is:</p>
<p><img src='http://s0.wp.com/latex.php?latex=d%5E2+%3D+x%5E2+%2B+y%5E2&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='d^2 = x^2 + y^2' title='d^2 = x^2 + y^2' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=d%5E2+%3D+%7B%28x+-+0%29%7D%5E2+%2B+%7B%28y+-+p_y%29%7D%5E2+%3D+x%5E2+%2B+y%5E2+-+%7Bp_y%7D%5E2+-+2%5Ccdot+p_y+y&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='d^2 = {(x - 0)}^2 + {(y - p_y)}^2 = x^2 + y^2 - {p_y}^2 - 2&#92;cdot p_y y' title='d^2 = {(x - 0)}^2 + {(y - p_y)}^2 = x^2 + y^2 - {p_y}^2 - 2&#92;cdot p_y y' class='latex' />, and <img src='http://s0.wp.com/latex.php?latex=d%5E2+%3D+%7B%28x+-+q_x%29%7D%5E2+%2B+%7B%28y-+q_y%29%7D%5E2+%3D+x%5E2+%2B+y%5E2+%2B+%7Bq_x%7D%5E2+%2B+%7Bq_y%7D%5E2+-+2+q_x+x+-+2+q_y+y.&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='d^2 = {(x - q_x)}^2 + {(y- q_y)}^2 = x^2 + y^2 + {q_x}^2 + {q_y}^2 - 2 q_x x - 2 q_y y.' title='d^2 = {(x - q_x)}^2 + {(y- q_y)}^2 = x^2 + y^2 + {q_x}^2 + {q_y}^2 - 2 q_x x - 2 q_y y.' class='latex' /></p>
<p>Solving for y, we have <img src='http://s0.wp.com/latex.php?latex=y+%3D+p_y%2F2&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='y = p_y/2' title='y = p_y/2' class='latex' />, using this we can solve for x, which yields <img src='http://s0.wp.com/latex.php?latex=x+%3D+%5Cfrac%7B%7B%5C%7Cq%5C%7C%7D%5E2+-+q_y+p_y%7D%7B2+q_x%7D.&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='x = &#92;frac{{&#92;|q&#92;|}^2 - q_y p_y}{2 q_x}.' title='x = &#92;frac{{&#92;|q&#92;|}^2 - q_y p_y}{2 q_x}.' class='latex' /> Finally we also have <img src='http://s0.wp.com/latex.php?latex=d+%3D+%5Csqrt%7Bx%5E2+%2B+y%5E2%7D&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='d = &#92;sqrt{x^2 + y^2}' title='d = &#92;sqrt{x^2 + y^2}' class='latex' />, which finishes our computation.</p>
<p>The below Javascript code implements the above computation and also adds the preprocessing steps of (1) translating the origin to <img src='http://s0.wp.com/latex.php?latex=p_0&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='p_0' title='p_0' class='latex' /> and (2) rotating the coordinate system so that <img src='http://s0.wp.com/latex.php?latex=p_1&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='p_1' title='p_1' class='latex' /> is of the form <img src='http://s0.wp.com/latex.php?latex=p_1+%3D+%280%2C+%7Bp_1%7D_y%29.&amp;bg=ffffff&amp;fg=111111&amp;s=0' alt='p_1 = (0, {p_1}_y).' title='p_1 = (0, {p_1}_y).' class='latex' /></p>
<pre class="brush: jscript; title: ; notranslate">
// return the unique disk with p1, p2, and p3 as boundary points.
function enclosingDisk3Points(_p1, _p2, _p3){

    var p1 = [_p1[0], _p1[1]];
    var p2 = [_p2[0], _p2[1]];
    var p3 = [_p3[0], _p3[1]];
    if (dist(p1, p3) &gt; dist(p1, p2)){
var p = p2;
p2 = p3;
p3 = p;
    }

    var p = p1;
    // make p1 the origin
    p2[0] = p2[0] - p1[0];
    p2[1] = p2[1] - p1[1];
    p3[0] = p3[0] - p1[0];
    p3[1] = p3[1] - p1[1];
    
    // apply rotation matrix to make p2.x = 0
    // the rotation matrix is
    // | p2[1]/dist(p2), -1 * p2[0]/dist(p2) |
    // | p2[0]/dist(p2), p2[1]/dist(p2) |
    //
    var original_p2 = [p2[0], p2[1]];
    p2[0] = 0;
    p2[1] = d(original_p2);

    // apply rotation matrix to p3
    var original_p3 = [p3[0], p3[1]]
    p3[0] = original_p2[1]/d(original_p2) * original_p3[0] - original_p2[0]/d(original_p2) * original_p3[1]
    p3[1] = original_p2[0]/d(original_p2) * original_p3[0] + original_p2[1]/d(original_p2) * original_p3[1]

    // the unique disk with the points p1, p2, and p3 as boundary points is
    // defined by the equation y = p2.y/2 &amp; x = (d(p3)^2 + p3.y * p2.y)/(2 * p3.x)
    var y = p2[1]/2.0;
    var x = (d(p3) * d(p3) - p3[1] * p2[1])/(2 * p3[0]);

    // apply inverse of rotation matrix
    var rotated_x = original_p2[1]/d(original_p2) * x + original_p2[0]/d(original_p2) * y
    var rotated_y = -1 * original_p2[0]/d(original_p2) * x + original_p2[1]/d(original_p2) * y;

    // translate back
    rotated_x = rotated_x + p1[0];
    rotated_y = rotated_y + p1[1];
    
    var radius = d([rotated_x - p1[0], rotated_y - p1[1]]);
    return [[rotated_x, rotated_y], radius];
    
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/807/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/807/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=807&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2012/10/06/computing-the-smallest-enclosing-disk/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>

		<media:content url="http://bloggingmath.files.wordpress.com/2012/10/center-point2.png" medium="image">
			<media:title type="html">center point</media:title>
		</media:content>
	</item>
		<item>
		<title>Solving Tangrams Using JTS</title>
		<link>http://bloggingmath.wordpress.com/2012/09/24/solving-tangrams-using-jts/</link>
		<comments>http://bloggingmath.wordpress.com/2012/09/24/solving-tangrams-using-jts/#comments</comments>
		<pubDate>Mon, 24 Sep 2012 01:49:01 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Computational Geometry]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[java topology suite]]></category>
		<category><![CDATA[jts]]></category>
		<category><![CDATA[tangram]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=754</guid>
		<description><![CDATA[The project, 2dfit, solves Tangram puzzles using the Java Topology Suite (JTS). The algorithm implementation is based on what I outlined in item 3 of the post &#8220;http://bloggingmath.wordpress.com/2007/05/28/tangram-puzzle/&#8220;. The implementation difficulties are from using floating point arithmetic, which is not &#8230; <a href="http://bloggingmath.wordpress.com/2012/09/24/solving-tangrams-using-jts/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=754&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The project, <a href="https://github.com/bjwbell/2dfit" title="2dfit">2dfit</a>, solves Tangram puzzles using the Java Topology Suite (JTS). The algorithm implementation is based on what I outlined in item 3 of the post &#8220;<a href="http://bloggingmath.wordpress.com/2007/05/28/tangram-puzzle/" title="tangram-puzzle">http://bloggingmath.wordpress.com/2007/05/28/tangram-puzzle/</a>&#8220;. </p>
<p>The implementation difficulties are from using floating point arithmetic, which is not robust for geometric operations. The JTS library attempts to minimize this by a coordinate snapping technique. But for the operations used in solving Tangrams the provided snapping was not sufficient. </p>
<p>There&#8217;s an option in JTS to specify the snapping tolerance (it has a fairly small default). I added small wrapper functions for the two operations of Boolean intersection and Boolean difference. The wrapper functions apply successively larger snapping tolerances up to a factor of epsilon, where epsilon = 1e-5. The below code shows the wrapper functions (in the code, g1 is the Tangram and g2 is a puzzle piece). </p>
<pre class="brush: java; title: ; notranslate">
    public static Geometry SemiRobustGeoOp(Geometry g1, Geometry g2, int op) throws Exception {
        double e1 = EPSILON/10;
        double snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(g1, g2);
        while (snapTolerance &amp;lt; e1) {
            try {
                Geometry[] geos = GeometrySnapper.snap(g1, g2, snapTolerance);
                switch (op) {                    
                case DIF_OP:   // difference
                    return geos[0].difference(geos[1]);
                case UNION_OP: // union
                    return geos[0].union(geos[1]);
                default:
                    throw new Exception(&amp;quot;unhandled semirobustgeoop: &amp;quot; + op);
                }
            } catch (TopologyException e){
                snapTolerance *= 2;
            }
        }
        return null;
    }

    public static boolean SemiRobustGeoPred(Geometry g1, Geometry g2, int pred) throws Exception {
        double e1 = EPSILON/10;
        double snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(g1, g2);
        while (snapTolerance &amp;lt; e1) {
            try {
                Geometry[] geos = GeometrySnapper.snap(g1, g2, snapTolerance);
                switch (pred) {                    
                case COVER_PRED: // 
                    return geos[0].covers(geos[1]);
                default:
                    throw new Exception(&amp;quot;unhandled semirobustgeopred: &amp;quot; + pred);
                }
            } catch (TopologyException e){
                snapTolerance *= 2;
            }
        }
        return false;
    }
</pre>
<p>Using the wrapper functions was key to a more robust implementation. The below figure shows a solved Tangram puzzle (from Test.java:FitTest_ToSingleLargeTriangle()), in the figure the puzzle pieces are labeled l1.dat, l2.dat,&#8230;, l7.dat (I was lazy in naming the files). It&#8217;s the result of running FitTest_ToSingleLargeTriange() in Test.java and plotting the result using gnuplot.<br />
<img src="http://bloggingmath.files.wordpress.com/2012/09/fitted-triangle.png?w=908"></p>
<p>I used the symmetry of each puzzle piece and a heuristic for choosing which puzzle piece to fit in reducing the number of permutations used for solving a Tangram.</p>
<p>For the puzzle piece symmetry, I used that the square is completely symmetric so only its first line segment needs to be used when fitting it. The triangle pieces are only partially symmetric so two of their three line segments need to be tried. </p>
<p>The below figure illustrates the symmetry of the square:</p>
<p><img src="https://docs.google.com/drawings/pub?id=1RCXDnYteEE2dKRImJ9U3lwN_X4STQu_BEMHa7eWnjGA&amp;w=409&amp;h=536"></p>
<p>I used two heuristics for which pieces to try fitting, first try larger pieces before smaller ones and two skip a piece if another identical piece has already failed to be fitted (there are two identical small triangles and similarly two identical large triangles).</p>
<p>With the above two optimizations it takes ~1min to solve a Tangram. Without the optimizations the algorithm did not complete for the Tangrams I tried.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/754/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/754/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=754&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2012/09/24/solving-tangrams-using-jts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>

		<media:content url="http://bloggingmath.files.wordpress.com/2012/09/fitted-triangle.png" medium="image" />

		<media:content url="https://docs.google.com/drawings/pub?id=1RCXDnYteEE2dKRImJ9U3lwN_X4STQu_BEMHa7eWnjGA&#38;w=409&#38;h=536" medium="image" />
	</item>
		<item>
		<title>River Flow Forecasting Using Support Vector Machines</title>
		<link>http://bloggingmath.wordpress.com/2011/11/07/river-flow-forecasting-using-support-vector-machines/</link>
		<comments>http://bloggingmath.wordpress.com/2011/11/07/river-flow-forecasting-using-support-vector-machines/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 14:03:04 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[machine learning]]></category>
		<category><![CDATA[river flow forecasting]]></category>
		<category><![CDATA[riverflow forecasts]]></category>
		<category><![CDATA[support vector machine]]></category>
		<category><![CDATA[svm]]></category>
		<category><![CDATA[weka]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=742</guid>
		<description><![CDATA[Over the past few months I and a colleague (Brian Wallace) have been working on a river flow forecasting paper. A draft version is available @ River Flow Paper. The goal of our work was to beat the current forecast &#8230; <a href="http://bloggingmath.wordpress.com/2011/11/07/river-flow-forecasting-using-support-vector-machines/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=742&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Over the past few months I and a colleague (Brian Wallace) have been working on a river flow forecasting paper. A draft version is available @ <a href="http://dl.dropbox.com/u/171910/paper/icmla_paper.pdf">River Flow Paper</a>. </p>
<p>The goal of our work was to beat the current forecast methods used by the Department of Water Resources for the April through July American River flow. The Department of Water Resources uses an aggregation of human judgement and linear regression equations for generating their forecasts. Given their methods they are surprisingly hard to beat!</p>
<p>We spent a few months trying different Machine Learning methods with little success. Many of the methods we tried resulted in forecasts that were significantly worse than the current forecasts, a few methods such as a properly trained neural network  gave forecasts that were comparable to the current forecasts. Finally, I decided to use a Support Vector Machine (SVM) for producing forecasts, after testing a large combination of parameters the forecasts started being significantly better than the current ones. </p>
<p>The data we used for generating forecasts is available online @ <a href="https://github.com/bjwbell/California-Water-Runoff-Forecasting">https://github.com/bjwbell/California-Water-Runoff-Forecasting</a>. The takeaway message is that we improved the forecast relative error from ~65% to ~48%. The below table shows the forecasts for the last 10 years. </p>
<table style="background-color:#ffffff;border:1px solid #c3c3c3;border-collapse:collapse;">
<caption>SVM Forecasts 2001-2010</caption>
<tr bgcolor="Snow">
<td> Year </td>
<td>     Actual (AcreFt)&nbsp;&nbsp; </td>
<td>  Predicted (AcreFt)&nbsp;&nbsp; </td>
<td>      |Error| (AcreFt)&nbsp;&nbsp; </td>
</tr>
<tr bgcolor="Lavender">
<td>2001&nbsp;&nbsp;&nbsp;</td>
<td>      552,626</td>
<td>   689,472</td>
<td>    136,846 </td>
</tr>
<tr bgcolor="Snow">
<td>2002&nbsp;&nbsp;&nbsp;</td>
<td>      973,817</td>
<td> 1,028,681</td>
<td>     54,864  </td>
</tr>
<tr bgcolor="Lavender">
<td>2003&nbsp;&nbsp;&nbsp;</td>
<td>    1,354,434</td>
<td>   459,476</td>
<td>    894,957 </td>
</tr>
<tr bgcolor="Snow">
<td>2004&nbsp;&nbsp;&nbsp;</td>
<td>      632,159</td>
<td>   713,440</td>
<td>     81,281</td>
</tr>
<tr bgcolor="Lavender">
<td>2005&nbsp;&nbsp;&nbsp;</td>
<td>    2,003,878</td>
<td> 1,844,360</td>
<td>    159,517 </td>
</tr>
<tr bgcolor="Snow">
<td>2006&nbsp;&nbsp;&nbsp;</td>
<td>    2,622,387</td>
<td> 2,315,193</td>
<td>    307,193 </td>
</tr>
<tr bgcolor="Lavender">
<td>2007&nbsp;&nbsp;&nbsp;</td>
<td>      522,651</td>
<td>   293,256</td>
<td>    229,394 </td>
</tr>
<tr bgcolor="Snow">
<td>2008&nbsp;&nbsp;&nbsp;</td>
<td>      674,287</td>
<td>   800,080</td>
<td>    125,793 </td>
</tr>
<tr bgcolor="Lavender">
<td>2009&nbsp;&nbsp;&nbsp;</td>
<td>    1,068,327</td>
<td> 1,253,523</td>
<td>    185,196 </td>
</tr>
<tr bgcolor="Snow">
<td>2010&nbsp;&nbsp;&nbsp;</td>
<td>     1,486,780</td>
<td> 1,023,649</td>
<td>    463,130 </td>
</tr>
<tr bgcolor="Lavender">
<td>    Mean </td>
<td>     1,189,135</td>
<td> 1,042,113</td>
<td>    263,817 </td>
</tr>
<tr></tr>
<tr bgcolor="Snow">
<td colspan="3">Root mean squared error</td>
<td><b>355,856</b></td>
</tr>
<tr bgcolor="Lavender">
<td colspan="3">Relative absolute error</td>
<td><b>48.65%</b></td>
</tr>
<tr bgcolor="Snow">
<td colspan="3">Root relative squared error</td>
<td><b>54.14%</b></td>
</tr>
</table>
<p>The forecasts currently used by the Department of Water Resources produced relative errors of 63.82% and root relative squared errors of 69.15%. Using modern methods for SVM&#8217;s gave us an increase in relative accuracy of over 15%! This was a fantastic result and shows the large payoff in keeping up with the state of art for something as ordinary as river flow forecasting.  </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/742/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/742/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=742&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2011/11/07/river-flow-forecasting-using-support-vector-machines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>
	</item>
		<item>
		<title>Book Review: The Art of R Programming</title>
		<link>http://bloggingmath.wordpress.com/2011/11/04/book-review-the-art-of-r-programming/</link>
		<comments>http://bloggingmath.wordpress.com/2011/11/04/book-review-the-art-of-r-programming/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 01:42:23 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Book Review]]></category>
		<category><![CDATA[book review]]></category>
		<category><![CDATA[Noam Matloff]]></category>
		<category><![CDATA[NoStarch Press]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=738</guid>
		<description><![CDATA[My former professor, Norm Matloff, wrote &#8220;The Art of R Programming&#8221; and NoStarch Press was kind enough to send me a review copy. The Art of R Programming is a straight forward explanation of R for programmers who are reasonably &#8230; <a href="http://bloggingmath.wordpress.com/2011/11/04/book-review-the-art-of-r-programming/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=738&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>My former professor, Norm Matloff, wrote &#8220;The Art of R Programming&#8221; and NoStarch Press was kind enough to send me a review copy. </p>
<p>The Art of R Programming is a straight forward explanation of R for programmers who are reasonably familiar with programming in another language. Matloff makes no assumptions of expertise in C or algorithms and his explanations are succinct and easy to follow. </p>
<p>If you&#8217;re aren&#8217;t familiar with R, it is a statistical programming language, with some similarities to Matlab.</p>
<p><strong>Rating 9/10</strong></p>
<p>The big advantages of R are (1) it&#8217;s high level, (2) reasonably easy to read, (3) functional in nature, (4) simple syntax. If you&#8217;re familiar with Python, it has a similar feel. Compared to complex languages such as C++, Java, etc, R is a breadth of fresh air due to the lightness of its syntax. That said as a programming language Python is nicer. R has a few annoyances (for me at least) that make it less pleasant to write in than Python.<br />
A couple of those are:</p>
<ul>
<li>Non-standard assignment operator e.g. to assign 5 to x in R we use &#8220;x &lt;- 5&quot; instead of the normal &quot;x = 5&quot; used in other languages. This is annoying because a significant amount of programming is doing assignments and a two character assignment operator is twice as much typing. Contrast this with Python which uses the plain &quot;x = 5&quot;.
<li>Vector creation using &#8220;c(1,2,3,4)&#8221;. Vectors in R are similar to lists in Python, it would be more natural to add a little syntactic sugar and use &#8220;[1,2,3,4]&#8221; for vector creation i.e. the same syntax as Python and many other languages.
</ul>
<p>The real reason to use R are its statistical libraries, it&#8217;s very widely used for statistics and is the most pleasant environment to work in.</p>
<p>The areas Matloff covers are:</p>
<table>
<tr>
<td>1 Why R?</td>
<td>2 Getting Started</td>
<td>3 Vectors</td>
</tr>
<tr>
<td>4 Matrices</td>
<td>5 Lists</td>
<td>6 Data Frames</td>
</tr>
<tr>
<td>7 Factors and Tables</td>
<td>8 R Programming Structures</td>
<td>9 R Functions</td>
</tr>
<tr>
<td>10 Doing Math in R</td>
<td>11 Input/Output</td>
<td>12 Object-Oriented Programming</td>
</tr>
<tr>
<td>13 Graphics</td>
<td>14 Debugging</td>
<td>15 Writing Fast R Code</td>
</tr>
<tr>
<td>16 Interfacing R to Other Languages</td>
<td>17 Parallel R</td>
<td>18 String Manipulation</td>
</tr>
<tr>
<td>19 Installation: R Base, New Packages</td>
<td>20 User Interfaces</td>
<td>21 To Learn More</td>
</tr>
</table>
<p>Much of the material is available online in tutorials such as John Cook&#8217;s, <a href="http://www.johndcook.com/R_language_for_programmers.html">R Language For Programmers</a>. The real gems are the chapters &#8220;Writing Fast R Code&#8221;, &#8220;Interfacing R to Other Languages&#8221;, and &#8220;Parallel R&#8221;. These chapters have great information that is not easily discoverable otherwise.</p>
<p>&#8220;The Art of R Programming&#8221; is a fun read, albeit somewhat specialized. If you need to do statistical work as a programmer I highly recommend buying it and spending an afternoon browsing it.  </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/738/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/738/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=738&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2011/11/04/book-review-the-art-of-r-programming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>
	</item>
		<item>
		<title>Haskell &amp; LLVM Talk</title>
		<link>http://bloggingmath.wordpress.com/2011/06/22/haskell-llvm-talk/</link>
		<comments>http://bloggingmath.wordpress.com/2011/06/22/haskell-llvm-talk/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 17:51:22 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Compilers]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[compilers]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[llvm]]></category>
		<category><![CDATA[lugod]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[talk]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=729</guid>
		<description><![CDATA[I did a talk at the Linux Users&#8217; Group of Davis yesterday evening that went very well. The QA and discussion afterwards was much better than previous talks I&#8217;ve given to students, the attendees from the Bay Area Haskell Users&#8217;s &#8230; <a href="http://bloggingmath.wordpress.com/2011/06/22/haskell-llvm-talk/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=729&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I did a talk at the <a href="http://lugod.org/">Linux Users&#8217; Group of Davis</a> yesterday evening that went very well. The QA and discussion afterwards was much better than previous talks I&#8217;ve given to students, the attendees from the Bay Area Haskell Users&#8217;s group were very sharp and had good comments. </p>
<p>Photos and slides are posted <a href="http://lugod.org/meeting/past/2011.06.20.php">here</a> and the slides are also viewable below.</p>
<iframe src="https://docs.google.com/present/embed?id=dfmgdj3_164ds3rddg6&amp;size=m" frameborder="0" width="555" height="451"  marginheight="0" marginwidth="0"></iframe>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/729/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=729&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2011/06/22/haskell-llvm-talk/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>
	</item>
		<item>
		<title>Book Review: Learn You a Haskell for Great Good!</title>
		<link>http://bloggingmath.wordpress.com/2011/05/09/book-review-learn-you-a-haskell-for-great-good/</link>
		<comments>http://bloggingmath.wordpress.com/2011/05/09/book-review-learn-you-a-haskell-for-great-good/#comments</comments>
		<pubDate>Mon, 09 May 2011 18:54:54 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[book review]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[learn you a haskell for great good]]></category>
		<category><![CDATA[no starch press]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=692</guid>
		<description><![CDATA[No Starch Press was kind enough to mail me a review copy of Learn You a Haskell for Great Good!. Rating: 10/10 Miran Lipovaca has done a fantastic job of writing a book aimed at beginning Haskell programmers. I like &#8230; <a href="http://bloggingmath.wordpress.com/2011/05/09/book-review-learn-you-a-haskell-for-great-good/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=692&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>No Starch Press was kind enough to mail me a review copy of <a href="http://nostarch.com/lyah.htm">Learn You a Haskell for Great Good!</a>.</p>
<p><strong>Rating: 10/10</strong></p>
<p>Miran Lipovaca has done a fantastic job of writing a book aimed at beginning Haskell programmers. I like his very straightforward writing style of introducing each topic with the minimum of complexity. </p>
<p>As you probably already know the book is available online for free at <a href="http://learnyouahaskell.com">http://learnyouahaskell.com</a> so the question becomes why purchase the dead tree copy? To be honest I don&#8217;t recommend buying a dead tree copy if you have a Kindle. </p>
<p>To summarize there are three ways to read the book:</p>
<ul>
<li>Dead tree</li>
<li>EBook</li>
<li>Online</li>
</ul>
<p>My preference in order is the e-book on the Kindle, the dead tree version, and finally the online version. For some reason I don&#8217;t like the formatting of the online version as much as either the dead tree version or the ebook. It&#8217;s partly because I have a harder time reading books on the computer than either on the Kindle or in paper back.<br />
No Starch did a great job of printing &#8220;Learn You a Haskell for Great Good!&#8221; on quality paper and the binding is excellent. As with all previous No Starch books I&#8217;ve purchased the physical layout and ink quality of the book are both excellent.  </p>
<p>The table of contents is:</p>
<ul>
<li>1. Introduction</li>
<li>2. Starting Out</li>
<li>3. Types and Typeclasses</li>
<li>4. Syntax in Functions</li>
<li>5. Recursion</li>
<li>6. Higher Order Functions</li>
<li>7. Modules</li>
<li>8. Making Our Own Types and Typeclasses</li>
<li>9. Input and Output</li>
<li>10. Functionally Solving Problems</li>
<li>11. Functors, Applicative Functors and Monoids</li>
<li>12. A Fistful of Monads</li>
<li>13. For a Few Monads More</li>
<li>14. Zippers</li>
</ul>
<p>Miran does an amazing job of keeping each chapter short and interspersing lighthearted comments. The table of contents should be self explanatory, as you can see he covers mostly just the fundamentals of Haskell and ends with Monads. There is the extra chapter on zippers which seems like an afterthought. </p>
<p>Comparing this book to <a href="http://book.realworldhaskell.org/">Real World Haskell</a>, they serve slightly different purposes. &#8220;Real World Haskell&#8221; assumes that you are already reasonably proficient as a programmer whereas this book introduces each topic without assuming much programming background knowledge. Also &#8220;Learn You a Haskell for Great Good!&#8221; is meant less as a reference text and more for reading from start to end. They are both fantastic books and I highly recommend reading both of them. &#8220;Learn You a Haskell for Great Good!&#8221; is a gentler introduction to Haskell and I recommend reading it first.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/692/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=692&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2011/05/09/book-review-learn-you-a-haskell-for-great-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Emacs As Your SQL Interface</title>
		<link>http://bloggingmath.wordpress.com/2011/02/03/using-emacs-as-your-sql-interface/</link>
		<comments>http://bloggingmath.wordpress.com/2011/02/03/using-emacs-as-your-sql-interface/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 00:15:46 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[texteditor]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=671</guid>
		<description><![CDATA[As part of learning a single editor well (Pragmatic Programmer Tips), I&#8217;ve switched to using Emacs as my interface to SQL Server. Most of the following tips work equally well for using Emacs with other SQL databases besides MS SQL &#8230; <a href="http://bloggingmath.wordpress.com/2011/02/03/using-emacs-as-your-sql-interface/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=671&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As part of learning a single editor well (<a href="http://www.pragmaticprogrammer.com/the-pragmatic-programmer/extracts/tips">Pragmatic Programmer Tips</a>), I&#8217;ve switched to using Emacs as my interface to SQL Server. </p>
<p>Most of the following tips work equally well for using Emacs with other SQL databases besides MS SQL Server. </p>
<h3>How to connect to SQL Server using Emacs</h3>
<p>First you need to connect to a database. The command for connecting to a MS SQL Server instance is &#8220;sql-ms&#8221;.<br />
Once you&#8217;ve entered the connection information Emacs opens a SQL query buffer, in which you can type SQL commands. <strong>After you type a SQL command, don&#8217;t forgot to enter &#8220;go&#8221; to execute the command.</strong></p>
<h3>Helpful commands for retrieving schema information</h3>
<p>	<b>1. select * from sys.tables </b><br />
Display the list of database tables</p>
<p>
        <b>2. select left(column_name, 35), left(data_type, 15), is_nullable from information_schema.columns where table_name=&#8217;tablename&#8217;</b><br />
Display the column names and column data-types for the table, &#8216;tablename&#8217;.</p>
<p>        <b>3. select left(CONSTRAINT_NAME, 100), CONSTRAINT_TYPE FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE table_name=&#8217;tablename&#8217; </b><br />
Display the constraints for table, &#8216;tablename&#8217;.</p>
<p>         <b>4. select left(@@servername, 25), left(DB_NAME(), 25)</b><br />Display the database server name and the database name.</p>
<h3>Improving Data Display</h3>
<p>To improve line wrapping execute &#8220;M-x toggle-truncate-lines&#8221;, this prevents the soft line wrapping that Emacs normally does and improves the display of long lines. </p>
<p>To make the display of wide columns (such as varchar or char(8000)) readable use <b>select left(columnName, 25) from table</b>, this truncates the column width to 25 characters. </p>
<h3>Useful Shortcuts</h3>
<p>Because sql-ms and the other sql providers inherit from comint you can use all the nice emacs command line shortcuts. I use &#8220;C-c-l&#8221; to list the command history, &#8220;M-p&#8221; and &#8220;M-n&#8221; to cycle through commands, and &#8220;sql-send-buffer&#8221; (C-c-C-b) to send a buffer to the *SQL* mode buffer, this is extremely useful if I&#8217;m trying to tweak a large query.  Use sql-set-sqli-buffer to set the SQL interactive buffer that&#8217;s used by sql-send-buffer.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/671/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/671/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=671&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2011/02/03/using-emacs-as-your-sql-interface/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>
	</item>
		<item>
		<title>2010 in Review</title>
		<link>http://bloggingmath.wordpress.com/2011/01/02/2010-in-review/</link>
		<comments>http://bloggingmath.wordpress.com/2011/01/02/2010-in-review/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 08:58:14 +0000</pubDate>
		<dc:creator>Bryan Bell</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://bloggingmath.wordpress.com/?p=662</guid>
		<description><![CDATA[I got this kinda of cool email about my blog stats. The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health: The Blog-Health-o-Meter&#8482; reads Wow. &#8230; <a href="http://bloggingmath.wordpress.com/2011/01/02/2010-in-review/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=662&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I got this kinda of cool email about my blog stats.</p>
<p>The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here&#8217;s a high level summary of its overall blog health:</p>
<p align="center"><img style="border:1px solid #ddd;background:#f5f5f5;padding:20px;" src="http://s0.wp.com/i/annual-recap/meter-healthy5.gif" width="250" height="183" alt="Healthy blog!"></p>
<p align="center">The <em>Blog-Health-o-Meter&trade;</em> reads Wow.</p>
<h2>Crunchy numbers</h2>
<div style="width:288px;float:right;border:1px solid #ddd;background:#fff;margin:0 0 1em 1em;padding:6px;">
<p>				<img src="http://s0.wp.com/i/annual-recap/abstract-stats-2.png" alt="Featured image" /><br />
				<br /><em>A helper monkey made this abstract painting, inspired by your stats.</em></p></div>
<p>The average container ship can carry about 4,500 containers.  This blog was viewed about <strong>18,000</strong> times in 2010.  If each view were a shipping container, your blog would have filled about 4 fully loaded ships.</p>
<p>
<p>In 2010, there were <strong>16</strong> new posts, growing the total archive of this blog to 74 posts.</p>
<p>The busiest day of the year was January 20th with <strong>673</strong> views. The most popular post that day was <a style="color:#08c;" href="http://bloggingmath.wordpress.com/2010/01/20/writing-a-compiler-in-haskell-compiler-series-part-i/">Writing A Compiler In Haskell (Compiler Series Part I)</a>.</p>
<p></p>
<h2>Where did they come from?</h2>
<p>The top referring sites in 2010 were <strong>reddit.com</strong>, <strong>en.wordpress.com</strong>, <strong>moodle.cs.ualberta.ca</strong>, <strong>blog.llvm.org</strong>, and <strong>mail.live.com</strong>.</p>
<p>Some visitors came searching, mostly for <strong>line segment intersection</strong>, <strong>writing a compiler in haskell</strong>, <strong>nginx asp.net</strong>, <strong>nginx mono</strong>, and <strong>mono nginx</strong>.</p>
<div style="clear:both;"></div>
<h2>Attractions in 2010</h2>
<p>These are the posts and pages that got the most views in 2010.</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">1</div>
<p>					<a style="margin-right:10px;" href="http://bloggingmath.wordpress.com/2010/01/20/writing-a-compiler-in-haskell-compiler-series-part-i/">Writing A Compiler In Haskell (Compiler Series Part I)</a> <span style="color:#999;font-size:8pt;">January 2010</span><br />11 comments											</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">2</div>
<p>					<a style="margin-right:10px;" href="http://bloggingmath.wordpress.com/2009/05/29/line-segment-intersection/">Line Segment Intersection</a> <span style="color:#999;font-size:8pt;">May 2009</span><br />6 comments											</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">3</div>
<p>					<a style="margin-right:10px;" href="http://bloggingmath.wordpress.com/2010/04/06/having-fun-with-happy-compiler-series-part-iii/">Having Fun with Happy (Compiler Series Part III)</a> <span style="color:#999;font-size:8pt;">April 2010</span><br />4 comments											</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">4</div>
<p>					<a style="margin-right:10px;" href="http://bloggingmath.wordpress.com/2009/02/13/configuring-mono-and-aspnet-on-nginx/">Configuring Mono and ASP.Net on Nginx</a> <span style="color:#999;font-size:8pt;">February 2009</span><br />3 comments											</p>
<div style="clear:left;float:left;font-size:24pt;line-height:1em;margin:-5px 10px 20px 0;">5</div>
<p>					<a style="margin-right:10px;" href="http://bloggingmath.wordpress.com/2010/01/28/playing-with-alex-compiler-series-part-ii/">Playing with Alex (Compiler Series Part II)</a> <span style="color:#999;font-size:8pt;">January 2010</span><br />4 comments											</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bloggingmath.wordpress.com/662/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bloggingmath.wordpress.com/662/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bloggingmath.wordpress.com&#038;blog=354208&#038;post=662&#038;subd=bloggingmath&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://bloggingmath.wordpress.com/2011/01/02/2010-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/01bd809fb0f4b9d644bf9e956fb14ba9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bjwbell</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/i/annual-recap/meter-healthy5.gif" medium="image">
			<media:title type="html">Healthy blog!</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/i/annual-recap/abstract-stats-2.png" medium="image">
			<media:title type="html">Featured image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
