<?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>Aaron Meurer&#039;s SymPy Blog</title>
	<atom:link href="http://asmeurersympy.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://asmeurersympy.wordpress.com</link>
	<description>My blog on my work on SymPy and other fun stuff.</description>
	<lastBuildDate>Sat, 11 May 2013 17:46:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='asmeurersympy.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/51b9e231856e8bf6de4f10e8251149d5?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Aaron Meurer&#039;s SymPy Blog</title>
		<link>http://asmeurersympy.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://asmeurersympy.wordpress.com/osd.xml" title="Aaron Meurer&#039;s SymPy Blog" />
	<atom:link rel='hub' href='http://asmeurersympy.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How to make attributes un-inheritable in Python using descriptors</title>
		<link>http://asmeurersympy.wordpress.com/2013/04/06/how-to-make-attributes-un-inheritable-in-python-using-descriptors/</link>
		<comments>http://asmeurersympy.wordpress.com/2013/04/06/how-to-make-attributes-un-inheritable-in-python-using-descriptors/#comments</comments>
		<pubDate>Sat, 06 Apr 2013 02:49:13 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1282</guid>
		<description><![CDATA[For https://github.com/sympy/sympy/pull/1969, and previous work at https://github.com/sympy/sympy/pull/1901, we added the ability for the SymPy doctester to run or not run doctests conditionally depending on whether or not required external dependencies are installed. This means that for example we can doctest all the plotting examples without them failing when matplotlib is not installed. For functions, this [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1282&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>For <a href="https://github.com/sympy/sympy/pull/1969" rel="nofollow">https://github.com/sympy/sympy/pull/1969</a>, and previous work at <a href="https://github.com/sympy/sympy/pull/1901" rel="nofollow">https://github.com/sympy/sympy/pull/1901</a>, we added the ability for the SymPy doctester to run or not run doctests conditionally depending on whether or not required external dependencies are installed. This means that for example we can doctest all the plotting examples without them failing when matplotlib is not installed. </p>
<p>For functions, this is as easy as decorating the function with <code>@doctest_depends</code>, which adds the attribute <code>_doctest_depends_on</code> to the function with a list of what dependencies the doctest depends on. The doctest will then not run the doctest unless those dependencies are installed.</p>
<p>For classes, this is not so easy. Ideally, one could just define <code>_doctest_depends_on</code> as an attribute of the class. However, the issue is that with classes, we have inheritance. But if class <code>A</code> has a docstring with a doctest that depends on some modules, it doesn&#8217;t mean that a subclass <code>B</code> of <code>A</code> will have a doctest that does.  </p>
<p>Really, what we need to do is to decorate the docstring itself, not the class. Unfortunately, Python does not allow adding attributes to strings</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; a = &quot;&quot;
&gt;&gt;&gt; a.x = 1
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
AttributeError: 'str' object has no attribute 'x'
</pre>
<p>So what we have to do is to create a attribute that doesn&#8217;t inherit.  </p>
<p>I had for some time wanted to give <a href="http://docs.python.org/2/howto/descriptor.html">descriptors</a> in Python a try, since they are a cool feature, but also the second most complicated feature in Python (the first is metaclasses). If you don&#8217;t know what a descriptor is, I recommend reading <a href="http://python-history.blogspot.com/2010/06/inside-story-on-new-style-classes.html?m=1">this blog post</a> by Guido van Rossum, the creator of Python. It&#8217;s the best explanation of the feature there is.  </p>
<p>Basically, Python lets attributes define what happens when they are accessed (like <code>a.x</code>).  You may already know that objects can define how their attributes are accessed via <code>__getattr__</code>. This is different. With descriptors, the <em>attributes themselves</em> define what happens.  This may sound less useful, but in fact, it&#8217;s a very core feature of the language. </p>
<p>If you&#8217;ve ever wondered how <code>property</code>, <code>classmethod</code>, or <code>staticmethod</code> work in Python, the answer is descriptors. Basically, if you have something like</p>
<pre class="brush: python; title: ; notranslate">
class A(object):
    def f(self):
        return 1
    f = property(f)
</pre>
<p>Then <code>A().f</code> magically calls what would normally be <code>A().f()</code>. The way it works is that <code>property</code> defines the <code>__get__</code> method, which returns <code>f(obj)</code>, where <code>obj</code> is the calling object, here <code>A()</code> (remember in Python that the first argument of a method, usually called <code>self</code> is the object that calls the method).  </p>
<p>Descriptors can allow method to define arbitrary behavior when called, set, or deleted.  To make an attribute inaccessible to subclasses, then, you just need to define a descriptor that prevents the attribute from being accessed if the class of the calling object is not the original class.  Here is some code:</p>
<pre class="brush: python; title: ; notranslate">
class nosubclasses(object):
    def __init__(self, f, cls):
        self.f = f
        self.cls = cls
    def __get__(self, obj, type=None):
        if type == self.cls:
            if hasattr(self.f, '__get__'):
                return self.f.__get__(obj, type)
            return self.f
        raise AttributeError
</pre>
<p>it works like this</p>
<pre class="brush: python; title: ; notranslate">
In [2]: class MyClass(object):
   ...:     x = 1
   ...:

In [3]: MyClass.x = nosubclasses(MyClass.x, MyClass)

In [4]: class MySubclass(MyClass):
   ...:     pass
   ...:

In [5]: MyClass.x
Out[5]: 1

In [6]: MyClass().x
Out[6]: 1

In [80]: MySubclass.x
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-80-2b2f456dd101&gt; in &lt;module&gt;()
----&gt; 1 MySubclass.x

&lt;ipython-input-51-7fe1b5063367&gt; in __get__(self, obj, type)
      8                 return self.f.__get__(obj, type)
      9             return self.f
---&gt; 10         raise AttributeError

AttributeError:

In [81]: MySubclass().x
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-81-93764eeb9948&gt; in &lt;module&gt;()
----&gt; 1 MySubclass().x

&lt;ipython-input-51-7fe1b5063367&gt; in __get__(self, obj, type)
      8                 return self.f.__get__(obj, type)
      9             return self.f
---&gt; 10         raise AttributeError

AttributeError:
</pre>
<p>Note that by using the third argument to <code>__get__</code>, this works regardless if the attribute is accessed from the class or the object. I have to call <code>__get__</code> on <code>self.f</code> again if it has it to ensure that the right thing happens if the attribute has other descriptor logic defined (and note that regular methods have descriptor logic defined&#8212;that&#8217;s how they convert the first argument <code>self</code> to implicitly be the calling object).</p>
<p>One could easily make class decorator that automatically adds the attribute to the class in a non-inheritable way:</p>
<pre class="brush: python; title: ; notranslate">
def nosubclass_x(args):
    def _wrapper(cls):
        cls.x = nosubclasses(args, cls)
        return cls
    return _wrapper
</pre>
<p>This automatically adds the property <code>x</code> to the decorated class with the value given in the decorator, and it won&#8217;t be accessible to subclasses:</p>
<pre class="brush: python; title: ; notranslate">
In [87]: @nosubclass_x(1)
   ....: class MyClass(object):
   ....:     pass
   ....:

In [88]: MyClass().x
Out[88]: 1

In [89]: MySubclass().x
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-89-93764eeb9948&gt; in &lt;module&gt;()
----&gt; 1 MySubclass().x

&lt;ipython-input-51-7fe1b5063367&gt; in __get__(self, obj, type)
      8                 return self.f.__get__(obj, type)
      9             return self.f
---&gt; 10         raise AttributeError

AttributeError:
</pre>
<p>For SymPy, we can&#8217;t use class decorators because we still support Python 2.5, and they were introduced in Python 2.6. The best work around is to just call <code>Class.attribute = nosubclasses(Class.attribute, Class)</code> after the class definition. Unfortunately, you can&#8217;t access a class inside its definition like you can with functions, so this has to go at the end. </p>
<p><strong>Name Mangling</strong></p>
<p>After coming up with all this, I remembered that Python already has a pretty standard way to define attributes in such a way that subclasses won&#8217;t have access to them. All you have to do is use two underscores before the name, like <code>__x</code>, and it will be <a href="http://docs.python.org/2/reference/expressions.html#atom-identifiers">name mangled</a>. This means that the name will be renamed to <code>_classname__x</code> outside the class definition. The name will not be inherited by subclasses.  There are some subtleties with this, particularly for strange class names (names that are too long, or names that begin with an underscore). I <a href="http://stackoverflow.com/q/15845931/161801">asked about this on StackOverflow</a>. The best answer is that there was a function in the standard library, but it was removed in Python 3. My tests reveal that the behavior is different in CPYthon than in PyPy, so getting it right for every possible class is nontrivial. The descriptor thing should work everywhere, though.  On the other hand, <code>getattr(obj, '_' + obj.__class__.__name__ + attributename)</code> will work 99% of the time, and is much easier both to write and to understand than the descriptor. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1282&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2013/04/06/how-to-make-attributes-un-inheritable-in-python-using-descriptors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
		<item>
		<title>When does x^log(y) = y^log(x)?</title>
		<link>http://asmeurersympy.wordpress.com/2013/03/03/when-does-xlogy-ylogx/</link>
		<comments>http://asmeurersympy.wordpress.com/2013/03/03/when-does-xlogy-ylogx/#comments</comments>
		<pubDate>Sun, 03 Mar 2013 06:49:35 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1218</guid>
		<description><![CDATA[In this blog post, when I write , I mean the natural logarithm, or log base , i.e., . A discussion on a&#160;pull request&#160;got me thinking about this question: what are the solutions to the complex equation ? &#160;At the outset, they look like different expressions. &#160;But clearly there some solutions. For example, if , [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1218&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><em>In this blog post, when I write <img src='http://s0.wp.com/latex.php?latex=%5Clog%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(x)' title='&#92;log(x)' class='latex' />, I mean the natural logarithm, or log base <img src='http://s0.wp.com/latex.php?latex=e&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='e' title='e' class='latex' />, i.e., <img src='http://s0.wp.com/latex.php?latex=%5Cln%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;ln(x)' title='&#92;ln(x)' class='latex' />.</em></p>
<p>A discussion on a&nbsp;<a href="https://github.com/sympy/sympy/pull/1845">pull request</a>&nbsp;got me thinking about this question: what are the solutions to the complex equation <img src='http://s0.wp.com/latex.php?latex=x%5E%7B%5Clog%7B%28y%29%7D%7D+%3D+y%5E%7B%5Clog%28x%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x^{&#92;log{(y)}} = y^{&#92;log(x)}' title='x^{&#92;log{(y)}} = y^{&#92;log(x)}' class='latex' />? &nbsp;At the outset, they look like different expressions. &nbsp;But clearly there some solutions. For example, if <img src='http://s0.wp.com/latex.php?latex=x+%3D+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = y' title='x = y' class='latex' />, then obviously the two expressions will be the same. &nbsp;We probably should exclude <img src='http://s0.wp.com/latex.php?latex=x+%3D+y+%3D+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = y = 0' title='x = y = 0' class='latex' />, though note that even if <img src='http://s0.wp.com/latex.php?latex=0%5E%7B%5Clog%280%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='0^{&#92;log(0)}' title='0^{&#92;log(0)}' class='latex' /> is well-defined (probably if it is it is either 0 or complex <img src='http://s0.wp.com/latex.php?latex=%5Cinfty&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;infty' title='&#92;infty' class='latex' />), it will be the same well-defined value. But for the remainder of this blog post, I&#8217;ll assume that <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x' title='x' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' /> are nonzero.</p>
<p>Now, observe that if we apply <img src='http://s0.wp.com/latex.php?latex=%5Clog&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log' title='&#92;log' class='latex' /> to both sides of the equation, we get <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft%28x%5E%7B%5Clog%28y%29%7D%5Cright+%29%7D+%3D+%5Clog+%7B%5Cleft+%28y%5E%7B%5Clog%28x%29%7D%5Cright+%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left(x^{&#92;log(y)}&#92;right )} = &#92;log {&#92;left (y^{&#92;log(x)}&#92;right )}' title='&#92;log{&#92;left(x^{&#92;log(y)}&#92;right )} = &#92;log {&#92;left (y^{&#92;log(x)}&#92;right )}' class='latex' />. &nbsp;Now, supposing that we can apply the famous logarithm exponent rule, we would get <img src='http://s0.wp.com/latex.php?latex=%5Clog%28x%29%5Clog%28y%29+%3D+%5Clog%28y%29%5Clog%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(x)&#92;log(y) = &#92;log(y)&#92;log(x)' title='&#92;log(x)&#92;log(y) = &#92;log(y)&#92;log(x)' class='latex' />, which means that if additionally <img src='http://s0.wp.com/latex.php?latex=%5Clog&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log' title='&#92;log' class='latex' /> is one-to-one, we would have that the original expressions must be equal.</p>
<p>The second question, that of <a href="http://en.wikipedia.org/wiki/Injective_function">injectivity</a>, is easier to answer than the first, so I&#8217;ll address it first. &nbsp;Note that the complex exponential is not one-to-one, because for example <img src='http://s0.wp.com/latex.php?latex=e%5E0+%3D+e%5E%7B2%5Cpi+i%7D+%3D+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='e^0 = e^{2&#92;pi i} = 1' title='e^0 = e^{2&#92;pi i} = 1' class='latex' />. &nbsp;But we still define the complex logarithm as the &#8220;inverse&#8221; of the complex exponential. &nbsp;What this really means is that the complex logarithm is strictly speaking not a function, because it is not well-defined. Recall that the definition of one-to-one means that <img src='http://s0.wp.com/latex.php?latex=f%28x%29+%3D+f%28y%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f(x) = f(y)' title='f(x) = f(y)' class='latex' /> implies <img src='http://s0.wp.com/latex.php?latex=x+%3D+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = y' title='x = y' class='latex' />, and that the definition of well-defined is that <img src='http://s0.wp.com/latex.php?latex=x+%3D+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = y' title='x = y' class='latex' /> implies <img src='http://s0.wp.com/latex.php?latex=f%28x%29+%3D+f%28y%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f(x) = f(y)' title='f(x) = f(y)' class='latex' />. &nbsp;It is clear to see here that <img src='http://s0.wp.com/latex.php?latex=f&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f' title='f' class='latex' /> being one-to-one is the same as <img src='http://s0.wp.com/latex.php?latex=f%5E%7B-1%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f^{-1}' title='f^{-1}' class='latex' /> being well-defined and visa-versa (<img src='http://s0.wp.com/latex.php?latex=f%5E%7B-1%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='f^{-1}' title='f^{-1}' class='latex' /> here is the same loose definition of an inverse as saying that the complex logarithm is the inverse of the complex exponential).</p>
<p>So note that the complex logarithm is not well-defined exactly because the complex exponential is not one-to-one. &nbsp;We of course fix this problem by making it well-defined, i.e., it normally is multivalued, but we pick a single value consistently (i.e., we pick a <a href="http://en.wikipedia.org/wiki/Branch_point#Complex_logarithm">branch</a>), so that it is well-defined. &nbsp;For the remainder of this blog post, I will assume the standard choice of branch cut for the complex logarithm, i.e., the branch cut is along the negative axis, and we choose the branch where, for <img src='http://s0.wp.com/latex.php?latex=x+%3E+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x &gt; 0' title='x &gt; 0' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Clog%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(x)' title='&#92;log(x)' class='latex' /> is real and <img src='http://s0.wp.com/latex.php?latex=%5Clog%28-x%29+%3D+%5Clog%28x%29+%2B+i%5Cpi&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(-x) = &#92;log(x) + i&#92;pi' title='&#92;log(-x) = &#92;log(x) + i&#92;pi' class='latex' />.</p>
<p>My point here is that we automatically know that the complex logarithm is one-to-one because we know that the complex exponential is well-defined.</p>
<p>So our question boils down to, when does the identity <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft+%28z%5Ea%5Cright%29%7D+%3D+a+%5Clog%28z%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left (z^a&#92;right)} = a &#92;log(z)' title='&#92;log{&#92;left (z^a&#92;right)} = a &#92;log(z)' class='latex' /> hold? &nbsp;In SymPy, this identity is only applied by <code>expand_log()</code> or <code>logcombine()</code> when <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' /> is real and <img src='http://s0.wp.com/latex.php?latex=z&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z' title='z' class='latex' /> is positive, so let us assume that we know that it holds under those conditions. Note that it also holds for some other values too. &nbsp;For example, by our definition <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft+%28e%5E%7Bi%5Cpi%7D%5Cright%29%7D+%3D+%5Clog%28-1%29+%3D+%5Clog%281%29+%2B+i%5Cpi+%3D+i%5Cpi+%3D+i%5Cpi%5Clog%28e%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left (e^{i&#92;pi}&#92;right)} = &#92;log(-1) = &#92;log(1) + i&#92;pi = i&#92;pi = i&#92;pi&#92;log(e)' title='&#92;log{&#92;left (e^{i&#92;pi}&#92;right)} = &#92;log(-1) = &#92;log(1) + i&#92;pi = i&#92;pi = i&#92;pi&#92;log(e)' class='latex' />. &nbsp;For our example, this means that <img src='http://s0.wp.com/latex.php?latex=x+%3D+e&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = e' title='x = e' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=y+%3D+-1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = -1' title='y = -1' class='latex' /> is a non-trivial solution (non-trivial meaning <img src='http://s0.wp.com/latex.php?latex=x+%5Cneq+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x &#92;neq y' title='x &#92;neq y' class='latex' />). &nbsp; Actually, the way that the complex logarithm being the &#8220;inverse&#8221; of the complex exponential works is that <img src='http://s0.wp.com/latex.php?latex=e%5E%7B%5Clog%28x%29%7D+%3D+x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='e^{&#92;log(x)} = x' title='e^{&#92;log(x)} = x' class='latex' /> for all <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x' title='x' class='latex' /> (on the other hand <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft%28e%5Ex%5Cright%29%7D+%5Cneq+x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left(e^x&#92;right)} &#92;neq x' title='&#92;log{&#92;left(e^x&#92;right)} &#92;neq x' class='latex' /> in general), so that if <img src='http://s0.wp.com/latex.php?latex=x+%3D+e&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = e' title='x = e' class='latex' />, then <img src='http://s0.wp.com/latex.php?latex=x%5E%7B%5Clog%28y%29%7D+%3D+e%5E%7B%5Clog%28y%29%7D+%3D+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x^{&#92;log(y)} = e^{&#92;log(y)} = y' title='x^{&#92;log(y)} = e^{&#92;log(y)} = y' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y%5E%7B%5Clog%28x%29%7D+%3D+y%5E%7B%5Clog%28e%29%7D+%3D+y%5E1+%3D+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y^{&#92;log(x)} = y^{&#92;log(e)} = y^1 = y' title='y^{&#92;log(x)} = y^{&#92;log(e)} = y^1 = y' class='latex' />. &nbsp;In other words, <img src='http://s0.wp.com/latex.php?latex=x+%3D+e&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = e' title='x = e' class='latex' /> is always a solution, for any <img src='http://s0.wp.com/latex.php?latex=y%5C%2C+%28%5Cneq+0%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y&#92;, (&#92;neq 0)' title='y&#92;, (&#92;neq 0)' class='latex' /> (and similarly <img src='http://s0.wp.com/latex.php?latex=y+%3D+e&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = e' title='y = e' class='latex' /> for all <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x' title='x' class='latex' />). &nbsp;In terms of our question of when <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft%28z%5Ea%5Cright%29%7D+%3D+a%5Clog%28z%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left(z^a&#92;right)} = a&#92;log(z)' title='&#92;log{&#92;left(z^a&#92;right)} = a&#92;log(z)' class='latex' />, this just says that this always true for <img src='http://s0.wp.com/latex.php?latex=a+%3D+%5Clog%28e%29+%3D+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a = &#92;log(e) = 1' title='a = &#92;log(e) = 1' class='latex' />, regardless of <img src='http://s0.wp.com/latex.php?latex=z&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z' title='z' class='latex' />, which is obvious. &nbsp;We can also notice that this identity always holds for <img src='http://s0.wp.com/latex.php?latex=a+%3D+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a = 0' title='a = 0' class='latex' />, regardless of <img src='http://s0.wp.com/latex.php?latex=z&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z' title='z' class='latex' />. In terms of our original equation, this means that <img src='http://s0.wp.com/latex.php?latex=x+%3D+e%5E0+%3D+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = e^0 = 1' title='x = e^0 = 1' class='latex' /> is a solution for all <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' /> (and as before, <img src='http://s0.wp.com/latex.php?latex=y+%3D+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = 1' title='y = 1' class='latex' /> for all <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x' title='x' class='latex' />).</p>
<p>Note that <img src='http://s0.wp.com/latex.php?latex=z+%3E+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z &gt; 0' title='z &gt; 0' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' /> real corresponds to <img src='http://s0.wp.com/latex.php?latex=x%2C+y+%3E+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x, y &gt; 0' title='x, y &gt; 0' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=%5Clog%28x%29%2C+%5Clog%28y%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(x), &#92;log(y)' title='&#92;log(x), &#92;log(y)' class='latex' /> real, respectively, (which are the same condition). &nbsp;So we have so far that the following are solutions to <img src='http://s0.wp.com/latex.php?latex=x%5E%7B%5Clog%28y%29%7D+%3D+y%5E%7B%5Clog%28x%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x^{&#92;log(y)} = y^{&#92;log(x)}' title='x^{&#92;log(y)} = y^{&#92;log(x)}' class='latex' />:</p>
<ul>
<li><span style="line-height:13px;"><img src='http://s0.wp.com/latex.php?latex=x%2C+y+%3E+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x, y &gt; 0' title='x, y &gt; 0' class='latex' /></span></li>
<li><img src='http://s0.wp.com/latex.php?latex=x+%3D+y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = y' title='x = y' class='latex' /></li>
<li><img src='http://s0.wp.com/latex.php?latex=x+%3D+e&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = e' title='x = e' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' /> arbitrary</li>
<li><img src='http://s0.wp.com/latex.php?latex=y+%3D+e&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = e' title='y = e' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x' title='x' class='latex' /> arbitrary</li>
<li><img src='http://s0.wp.com/latex.php?latex=x+%3D+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = 1' title='x = 1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' /> arbitrary</li>
<li><img src='http://s0.wp.com/latex.php?latex=y+%3D+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = 1' title='y = 1' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x' title='x' class='latex' /> arbitrary</li>
</ul>
<p>Now let&#8217;s look at some cases where <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft+%28z%5Ea%5Cright%29%7D+%5Cneq+a%5Clog%28z%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left (z^a&#92;right)} &#92;neq a&#92;log(z)' title='&#92;log{&#92;left (z^a&#92;right)} &#92;neq a&#92;log(z)' class='latex' />. &nbsp;If <img src='http://s0.wp.com/latex.php?latex=z+%3C+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z &lt; 0' title='z &lt; 0' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' /> is a nonzero even integer, then <img src='http://s0.wp.com/latex.php?latex=z%5Ea+%3E+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z^a &gt; 0' title='z^a &gt; 0' class='latex' /> so <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft+%28z%5Ea+%5Cright%29%7D%29+%3D+%5Clog%7B%5Cleft+%28%5Cleft+%28-z%5Cright+%29%5Ea+%5Cright+%29%7D+%3D+a%5Clog%28-z%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left (z^a &#92;right)}) = &#92;log{&#92;left (&#92;left (-z&#92;right )^a &#92;right )} = a&#92;log(-z)' title='&#92;log{&#92;left (z^a &#92;right)}) = &#92;log{&#92;left (&#92;left (-z&#92;right )^a &#92;right )} = a&#92;log(-z)' class='latex' />, whereas <img src='http://s0.wp.com/latex.php?latex=a%5Clog%28z%29+%3D+a%28%5Clog%28-z%29+%2B+i%5Cpi%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a&#92;log(z) = a(&#92;log(-z) + i&#92;pi)' title='a&#92;log(z) = a(&#92;log(-z) + i&#92;pi)' class='latex' />, which are different by our assumption that <img src='http://s0.wp.com/latex.php?latex=a+%5Cneq+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a &#92;neq 0' title='a &#92;neq 0' class='latex' />. &nbsp;If <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' /> is an odd integer not equal to 1, then <img src='http://s0.wp.com/latex.php?latex=z%5Ea+%3C+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z^a &lt; 0' title='z^a &lt; 0' class='latex' />, so&nbsp;<img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft+%28z%5Ea+%5Cright%29%7D+%3D+%5Clog%7B%5Cleft+%28-z%5Ea+%5Cright+%29%7D+%2B+i%5Cpi&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left (z^a &#92;right)} = &#92;log{&#92;left (-z^a &#92;right )} + i&#92;pi' title='&#92;log{&#92;left (z^a &#92;right)} = &#92;log{&#92;left (-z^a &#92;right )} + i&#92;pi' class='latex' /> = $latex&nbsp;\log{\left (\left(- z\right)^{a} \right )} + i\pi$ <em>WordPress is refusing to render this. It should be</em> log((-z)^a) + iπ = <img src='http://s0.wp.com/latex.php?latex=a%5Clog%28-z%29+%2B+i%5Cpi&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a&#92;log(-z) + i&#92;pi' title='a&#92;log(-z) + i&#92;pi' class='latex' />, whereas <img src='http://s0.wp.com/latex.php?latex=a%5Clog%28z%29+%3D+a%28%5Clog%28-z%29+%2B+i%5Cpi%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a&#92;log(z) = a(&#92;log(-z) + i&#92;pi)' title='a&#92;log(z) = a(&#92;log(-z) + i&#92;pi)' class='latex' /> again, which is not the same because <img src='http://s0.wp.com/latex.php?latex=a+%5Cneq+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a &#92;neq 1' title='a &#92;neq 1' class='latex' />. This means that if we let <img src='http://s0.wp.com/latex.php?latex=x+%3C+0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x &lt; 0' title='x &lt; 0' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y+%3D+e%5Ea&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = e^a' title='y = e^a' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=a+%5Cneq+0%2C+1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a &#92;neq 0, 1' title='a &#92;neq 0, 1' class='latex' />, we get a non-solution (and the same if we swap <img src='http://s0.wp.com/latex.php?latex=x&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x' title='x' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=y&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y' title='y' class='latex' />).  </p>
<p>This is as far as I got tonight. WordPress is arbitrarily not rendering that LaTeX for no good reason.  That and the very ugly LaTeX images is pissing me off (why wordpress.com hasn&#039;t switched to MathJaX yet is beyond me).  The next time I get some free time, I am going to seriously consider switching my blog to something hosted on GitHub, probably using the IPython notebook.  I welcome any hints people can give me on that, especially concerning migrating pages from this blog.</p>
<p>Here is some work on finding the rest of the solutions: the general definition of <img src='http://s0.wp.com/latex.php?latex=%5Clog%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(x)' title='&#92;log(x)' class='latex' /> is <img src='http://s0.wp.com/latex.php?latex=%5Clog%28%7Cx%7C%29+%2B+i%5Carg%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(|x|) + i&#92;arg(x)' title='&#92;log(|x|) + i&#92;arg(x)' class='latex' />, where <img src='http://s0.wp.com/latex.php?latex=%5Carg%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;arg(x)' title='&#92;arg(x)' class='latex' /> is chosen in <img src='http://s0.wp.com/latex.php?latex=%28-%5Cpi%2C+%5Cpi%5D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='(-&#92;pi, &#92;pi]' title='(-&#92;pi, &#92;pi]' class='latex' />.  Therefore, if <img src='http://s0.wp.com/latex.php?latex=%5Clog%7B%5Cleft%28z%5Ea%5Cright+%29%7D+%3D+a%5Clog%28z%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log{&#92;left(z^a&#92;right )} = a&#92;log(z)' title='&#92;log{&#92;left(z^a&#92;right )} = a&#92;log(z)' class='latex' />, we must have <img src='http://s0.wp.com/latex.php?latex=%5Carg%28z%5Ea%29+%3D+a%5Carg%28z%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;arg(z^a) = a&#92;arg(z)' title='&#92;arg(z^a) = a&#92;arg(z)' class='latex' />.  I believe a description of all such complex <img src='http://s0.wp.com/latex.php?latex=z&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z' title='z' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' /> will give all solutions <img src='http://s0.wp.com/latex.php?latex=x+%3D+z&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = z' title='x = z' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=y+%3D+e%5Ea&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = e^a' title='y = e^a' class='latex' /> (and <img src='http://s0.wp.com/latex.php?latex=y+%3D+z&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='y = z' title='y = z' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=x+%3D+e%5Ea&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x = e^a' title='x = e^a' class='latex' />) to <img src='http://s0.wp.com/latex.php?latex=x%5E%7B%5Clog%28y%29%7D+%3D+y%5E%7B%5Clog%28x%29%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x^{&#92;log(y)} = y^{&#92;log(x)}' title='x^{&#92;log(y)} = y^{&#92;log(x)}' class='latex' />.  I need to verify that, though, and I also need to think about how to describe such <img src='http://s0.wp.com/latex.php?latex=z&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='z' title='z' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=a&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='a' title='a' class='latex' />. I will (hopefully) continue this post later, either by editing this one or writing a new one (depending on how much more I come up with).  </p>
<p>Any comments to this post are welcome.  I know you can&#039;t preview comments, but if you want to use math, just write it as <code>&#036;latex math&#036;</code> (like <code>&#036;latex \log(x)&#036;</code> for <img src='http://s0.wp.com/latex.php?latex=%5Clog%28x%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;log(x)' title='&#92;log(x)' class='latex' />). If you mess something up, I&#8217;ll edit your comment and fix it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1218/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1218&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2013/03/03/when-does-xlogy-ylogx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
		<item>
		<title>Tip for debugging SymPy with PuDB</title>
		<link>http://asmeurersympy.wordpress.com/2013/01/28/tip-for-debugging-sympy-with-pudb/</link>
		<comments>http://asmeurersympy.wordpress.com/2013/01/28/tip-for-debugging-sympy-with-pudb/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 00:43:49 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1204</guid>
		<description><![CDATA[Usually, when I debug SymPy code with PuDB, I create a script that calls the code, then I put a in the SymPy library code where I want to start debugging. But this is annoying, first because I have to create the script, and second, because I have to modify the library code, and there&#8217;s [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1204&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Usually, when I debug SymPy code with <a href="http://asmeurersympy.wordpress.com/2010/06/04/pudb-a-better-python-debugger/">PuDB</a>, I create a script that calls the code, then I put a </p>
<pre class="brush: python; title: ; notranslate">
import pudb; pudb.set_trace()
</pre>
<p>in the SymPy library code where I want to start debugging. But this is annoying, first because I have to create the script, and second, because I have to modify the library code, and there&#8217;s always the risk of accidentally commiting that.  Also, if I want to start debugging somewhere else, I have to edit the files and change it.</p>
<p>Well, I just figured out a better way.  <del datetime="2013-01-30T02:32:19+00:00">First, if you haven&#8217;t already, add an alias like this in your bash config file (<code>~/.profile</code> or <code>~/.bashrc</code>):<code>alias pudb='python -m pudb.run</code>.</del> <i>As of <a href="https://github.com/inducer/pudb/pull/54">this pull request</a>, this is no longer necessary.  A <code>pudb</code> script is installed automatically with PuDB.</i></p>
<p>This will let you run <code>pudb script.py</code> to debug <code>script.py</code>.  <del datetime="2013-02-05T04:22:39+00:00">Next, start PuDB. It doesn&#8217;t matter with what. You can just run <code>touch test.py</code>, and then <code>pudb test.py</code>.</del>  <i>It occured to me that you can just set the breakpoint when starting isympy with PuDB.</i></p>
<p>Now, press <code>m</code>, and navigate to where in the library code you want to start debugging.  It also helps to use <code>/</code> to search the current file and <code>L</code> to jump to a specific line.  When you get to the line where you want to start debugging, press <code>b</code> to set a breakpoint. You can do this in multiple places if you want.</p>
<p>Now, you just have to start <code>isympy</code> from within PuDB.  Just run <code>pudb bin/isympy</code>, and immediately press <code>c</code> to jump to the interactive prompt.  Now, run whatever code you want to debug.  When it gets to the breakpoint, PuDB will open, and you can start debugging.  If you type <code>c</code> to continue, it will go back to isympy. But the next time you run something that hits the breakpoint, it will open PuDB again. </p>
<p>This trick works because breakpoints are saved to file (at <code>~/.config/pudb/saved-breakpoints</code>). In fact, if you want, you can just modify that file in the first step.  You can edit your saved breakpoints in the bottom right pane of PuDB. </p>
<p>When you are done and you type <code>Ctrl-D</code> PuDB will pop-up again, asking if you want to quit.  That&#8217;s because it was running the whole time, underneath isympy.  Just press <code>q</code>.  Note that you should avoid pressing <code>q</code> while debugging, or else PuDB will quit, and you will be left with just normal isympy (it won&#8217;t break at your breakpoints any more).  Actually, if you do this, but doing <code>Ctrl-D</code> still opens the PuDB prompt, you can just press &#8220;Restart&#8221;, and it should start working again.  Note that &#8220;Restart&#8221; will not actually reset isympy:  all your saved variables will still be the same, and any changes to the library code will not be reloaded.  To do that, you have to completely exit and start over again.</p>
<p>Of course, there is nothing SymPy specific about this trick. As long as you have a script that acts as an entry point to an interactive console for your application, you can use it.  If you just use IPython, you can use something like <code>pudb /bin/ipython</code> (replace <code>/bin/ipython</code> with the output of <code>which ipython</code>).  </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1204/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1204&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2013/01/28/tip-for-debugging-sympy-with-pudb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
		<item>
		<title>Emacs: One year later</title>
		<link>http://asmeurersympy.wordpress.com/2013/01/01/emacs-one-year-later/</link>
		<comments>http://asmeurersympy.wordpress.com/2013/01/01/emacs-one-year-later/#comments</comments>
		<pubDate>Tue, 01 Jan 2013 09:51:21 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1168</guid>
		<description><![CDATA[As readers of this blog may remember, back in 2011, I decided to move to a command-line based editor. For roughly two weeks in December, 2011, I exclusively used Vim, and for the same amount of time in January, 2012, I used exclusively Emacs. I had used a little of each editor in the past, [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1168&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As readers of this blog may remember, back in 2011, I decided to move to a command-line based editor. For roughly two weeks in December, 2011, I exclusively used Vim, and for the same amount of time in January, 2012, I used exclusively Emacs. I had used a little of each editor in the past, but this was my first time using them to do true editing work. My experiences are chronicled in my blog posts (parts <a href="http://asmeurersympy.wordpress.com/2011/12/20/vim-vs-emacs-part-1/" title="1">1</a>, <a href="http://asmeurersympy.wordpress.com/2012/01/03/vim-vs-emacs-part-2/" title="2">2</a>, <a href="http://asmeurersympy.wordpress.com/2012/01/13/vim-vs-emacs-part-3/" title="3">3</a>, and <a href="http://asmeurersympy.wordpress.com/2012/07/09/emacs-7-months-later/" title="7 months later follow up">7 months later follow up</a>).  </p>
<p>To summarize, I decided to use Emacs, as I found it to be much more intuitive, and much more user-friendly.  Today, January 1, marks the one-year point of my using Emacs as my sole text editor, with some exceptions (notably, I&#8217;m currently writing this blog post in the browser).  So I&#8217;d like to make some observations:</p>
<li>Either one of these editors (Vim or Emacs) is going to really suck unless you are willing to make a serious investment in customizing them and installing nice addons. For the second point, Emacs has an advantage, because the philosophy of Vim is to be barebones whereas the philosophy of Emacs is to be featureful, so that in particular many things that were once addons of Emacs are now included in the standard installation.  For customization, on the one hand, Emacs is easier, because it has a nice interface (<code>M-x customize</code>), but on the other hand, Vim&#8217;s scripting language is much easier to hack on than Emacs lisp (I still can&#8217;t code in Lisp to save my life; it&#8217;s a very challenging programming language).
<p>But my point here is that neither has really great defaults. For example, in Emacs, <code>M-space</code> is bound to <code>just-one-space</code>, which is great for programming.  What it does is remove all spaces around the cursor, except for one.  But to be really useful, it also should include newlines.  It doesn&#8217;t do this by default.  Rather, you have to call it with a negative argument.  So to be really useful, you have to add</p>
<pre class="brush: plain; title: ; notranslate">
(defun just-one-space-with-newline ()
  &quot;Call just-one-space with a negative argument&quot;
  (interactive)
  (just-one-space -1))

(global-set-key (kbd &quot;M-SPC&quot;) 'just-one-space-with-newline)
</pre>
<p>to your <code>.emacs</code> file.</li>
<li>Emacs has great features, but I always have to look them up.  Or rather, I have to look up the keyboard shortcuts for them.  I only have the keyboard shortcuts memorized for the things I do every day.  I even ended up forgetting really important ones, like <code>M-w</code> (Emacs version of copy).  And if a feature involves several keystrokes to access, forget about it (for example, rectangular selection, or any features of special modes).  If I use a new mode, e.g., for some file type that I rarely edit (like HTML), I might as well not have any of the features, other than the syntax highlighting, because I either don&#8217;t know what they are, or even if I know that they should exist (like automatic tag completion for html), I have no idea how to access them.
<p>There&#8217;s really something to be said about GUI editors, which give these things to users in a way that they don&#8217;t have to memorize anything.  Perhaps I should try to use the menu more.  Or maybe authors of addons should aim to make features require as little cognitive user interaction as possible (such as the excellent <a href="http://cx4a.org/software/auto-complete/manual.html"><code>auto-complete-mode</code></a> I mentioned in <a href="http://asmeurersympy.wordpress.com/2012/01/13/vim-vs-emacs-part-3/">part 3</a>).</p>
<p> I mention this because it is one of the things I complained about with Vim, that the keybindings were too hard to memorize.  Of course, the difference with Vim is that one has to memorize keybindings to do even the most basic of editing tasks, whereas with Emacs one can always fall back to more natural things like <code>Shift-Arrow Key</code> to select text or <code>Delete</code> to delete the character under the cursor (and yes, I know you can rebind this stuff in Vim; I refer you to the previous bullet point). </li>
<li>I mentioned at the end of part 3 that Vim might still be useful to learn, as vi is available literally anywhere that you have POSIX.  I honestly don&#8217;t think I would be able to use vi or vim if I had to, customization or no, unless I had my keyboard cheat sheet and a decent amount of time.  If I&#8217;m stuck on a barebones system and I can&#8217;t do anything about it, I&#8217;ll use nano/pico before I use vi.  It&#8217;s not that I hate vi. I just can&#8217;t do anything with it. It is the same to me now as it was before I used it in-depth.  I have forgotten all the keyboard shortcuts, except for <code>ESC</code> and <code>i</code>.</li>
<li>I don&#8217;t use <code>emacsclient</code> any more.  Ever since I got my new retina MacBook Pro, I don&#8217;t need it any more, because with the solid state drive starting Emacs from scratch is instantaneous.  I&#8217;m glad to get rid of it, because it had some seriously annoying glitches.</li>
<li>Add <code>alias e=emacs</code> to your Bash config file (<code>.profile</code> or <code>.bashrc</code>). It makes life much easier. &#8220;emacs&#8221; is not an easy word to type, at least on QWERTY keyboards.</li>
<li>I still feel like I am not nearly as efficient in Emacs as I could be. On the one hand, I know there are built-in features (like rectangular selection) that I do not take advantage of enough.  I have been a bit lazy with customization: there are a handful of things that I do often that require several keystrokes, but I still haven&#8217;t created custom keyboard shortcuts for (off the top of my head: copying and pasting to/from the Mac OS X clipboard and rigidly indenting/dedenting a block of text (<code>C-u 4 C-x TAB</code>, actually <code>C-c u 4 C-x TAB</code>, since I did the sensible thing and rebound <code>C-u</code> to clear to the previous newline, and bound <code>universal-argument</code> to <code>C-c u</code>) come to mind).
<p>I feel as if I were to watch someone who has used Emacs for a long time that I would learn a lot of tricks.</li>
<li>I really should learn Emacs lisp. There are a lot of little customizations that I would like to make, but they are really niche, and can only be done programmatically.  But who has the time to learn a completely new programming language (plus a whole library, as just knowing Lisp is useless if you don&#8217;t know the proper Emacs funtions and variables and coding styles)?</li>
<li>I&#8217;ve still not found a good visual browser for jumping to function definitions in a file (mostly Python function definitions, but also other kinds of headers for other kinds of files).  The best I&#8217;ve found is <code>imenu</code>. If you know of anything, please let me know.  One thing I really liked about Vim was the <a href="http://www.vim.org/scripts/script.php?script_id=273">tag list</a> extension, which did this perfectly (thanks to commenter <a href="http://asmeurersympy.wordpress.com/2011/12/20/vim-vs-emacs-part-1/#comment-424">Scott</a> for pointing it out to me).  I&#8217;ve been told that Cedet has something like this, but every time I try to install it, I run into some issues that just seem like way too much work (I don&#8217;t remember what they are, it won&#8217;t compile or something, or maybe it just wants to do just way too much and I can&#8217;t figure out how to disable everything except for the parts I want).  </li>
<li>If you ever code in C, add the following to your Makefile
<pre class="brush: plain; title: ; notranslate">
check-syntax:
	$(CC) -o nul $(FLAGS) -S $(CHK_SOURCES)
</pre>
<p>(and if you don&#8217;t use a Makefile, start using one now).  This is assuming you have <code>CC</code> and <code>FLAGS</code> defined at the top (generally to something like <code>cc</code> and <code>-Wall</code>, respectively). Also, add the following to your <code>.emacs</code></p>
<pre class="brush: plain; title: ; notranslate">
;; ===== Turn on flymake-mode ====

(add-hook 'c-mode-common-hook 'turn-on-flymake)
(defun turn-on-flymake ()
  &quot;Force flymake-mode on. For use in hooks.&quot;
  (interactive)
  (flymake-mode 1))

(add-hook 'c-mode-common-hook 'flymake-keyboard-shortcuts)
(defun flymake-keyboard-shortcuts ()
  &quot;Add keyboard shortcuts for flymake goto next/prev error.&quot;
  (interactive)
  (local-set-key &quot;\M-n&quot; 'flymake-goto-next-error)
  (local-set-key &quot;\M-p&quot; 'flymake-goto-prev-error))
</pre>
<p>The last part adds the useful keyboard shortcuts <code>M-n</code> and <code>M-p</code> to move between errors.  Now, errors in your C code will show up automatically as you type.  If you use the command line version of emacs like I do, and not the GUI version, you&#8217;ll also need to install the <a href="http://www.emacswiki.org/emacs/flymake-cursor.el">flymake-cursor</a> module, which makes the errors show up in the mode line, since otherwise it tries to use mouse popups.  You can change the colors using <code>M-x customize-face</code> (search for &#8220;flymake&#8221;). </li>
<li>I never got flymake to work with LaTeX.  Does anyone know how to do it? It seems it is hardcoded to use MikTeX, the Windows version of LaTeX. I found some stuff, but none of it worked.
<p>Actually, what I really would like is not syntax checking (I rarely make syntax mistakes in LaTeX any more), but rather something that automatically builds the PDF constantly as I type.  That way, I can just look over at the PDF as I am writing (I use an external monitor for this. I highly recommend it if you use LaTeX, especially one of those monitors that swivels to portrait mode).  </li>
<li>If you use Mac OS X, you can use the very excellent <a href="http://pqrs.org/macosx/keyremap4macbook/">KeyRemap4MacBook</a> program to make regular Mac OS X programs act more like Emacs.  Mac OS X already has many Emacs shortcuts built in (like <code>C-a</code>, <code>C-e</code>, etc.), but that only works in Cocoa apps, and it doesn&#8217;t include any meta key shortcuts.  This lets you use additional shortcuts literally everywhere (don&#8217;t worry, it automatically doesn&#8217;t use them in the Terminal), including an emulator for <code>C-space</code> and some <code>C-x</code> commands (like <code>C-x C-s</code> to <code>Command-s</code>).  It doesn&#8217;t work on context sensitive shortcuts, unfortunately, unless the operating system already supports it with another keyboard shortcut (e.g., it can map <code>M-f</code> to <code>Option-right arrow</code>).  For example, it can&#8217;t enable moving between paragraphs with <code>C-S-{</code> and <code>C-S-}</code>.  If anyone knows how to do that, let me know. </li>
<li>For about a month this summer, I had to use a Linux laptop, because my Mac broke and my new Mac took a month to arrive (the downside to ordering a new computer immediately after it is announced by Apple).  At this point, my saving of all my customizations to <a href="http://pqrs.org/macosx/keyremap4macbook/">GitHub</a> really helped a lot.  I created a new branch for the Linux computer (because several things in my customizations were Mac specific), and just symlinked the files I wanted.  A hint I can give to people using Linux is to use Konsole.  The Gnome terminal sucks.  One thing I never figured out is how to make Konsole (or any other Terminal for that matter) to send Control-Shift shortcuts to Emacs (see <a href="http://superuser.com/q/439961/39697" rel="nofollow">http://superuser.com/q/439961/39697</a>).   I don&#8217;t use Linux any more at the moment, but if anyone knows what was going on there, add an answer to that question. </li>
<li>In <a href="http://asmeurersympy.wordpress.com/2012/01/13/vim-vs-emacs-part-3/">part 3</a> mentioned that <a href="http://www.dr-qubit.org/predictive/predictive-user-manual/html/index.php">predictive mode</a> was cool, but not very useful.  What it does is basically add tab completion for every word in the English language.  Actually, I&#8217;ve found using auto-complete-mode even when editing text (or LaTeX) to be very useful.  Unlike predictive mode, it only guesses words that you&#8217;ve already typed  (it turns out that you tend to type the same words over and over, and doubly so if those words are LaTeX math commands).  Also, predictive mode has a set order of words, which supposedly helps to use it with muscle memory, whereas auto-complete-mode tries to learn what words you are more likely to use based on some basic statistical machine-learning.  Also, auto-complete-mode has a much better visual UI and smarter defaults than predictive mode. The result is that it&#8217;s actually quite useful and makes typing plain text, as well as LaTeX (actually, pretty much anything, as long as you tend to use the same words repeatedly) much faster.  I recommend enabling auto-complete-mode almost everywhere using hooks, like
<pre class="brush: plain; title: ; notranslate">
(add-hook 'latex-mode-hook 'auto-complete-mode)
(add-hook 'LaTeX-mode-hook 'auto-complete-mode)
(add-hook 'prog-mode-hook 'auto-complete-mode)
;; etc.
</pre>
</li>
<li>At the end of the day, I&#8217;m pretty happy with Emacs.  I&#8217;ve managed to fix most of the things that make it annoying, and it is orders of magnitude more powerful than any GUI editor or IDE I&#8217;ve ever seen, especially at just basic text editing, which is the most important thing (I can always use another program for other things, like debugging or whatever).  The editor uses the basic shortcuts that I am used to, and is quite efficient to write in.  Extensions like auto-complete-mode make using it much faster, though I could use some more extensions to make it even better (namely, a better isearch and a better imenu). Regarding Vim vs. Emacs, I&#8217;d like to quote something I said back in my <a href="http://asmeurersympy.wordpress.com/2011/12/20/vim-vs-emacs-part-1">first blog post</a> about Vim over a year ago:<br />
<blockquote><p>Vim is great for text <em>editing</em>, but not so hot for text <em>writing</em> (unless you always write text perfectly, so that you never need to leave insert mode until you are done typing). Just the simple act of deleting a mistyped word (yes, word, that happens a lot when you are decently fast touch typist) takes several keystrokes, when it should in my opinion only take one (two if you count the meta-key).</p></blockquote>
<p>Needless to say, I find Emacs to be great for both text editing and text writing. </li>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1168/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1168&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2013/01/01/emacs-one-year-later/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
		<item>
		<title>2012 in review</title>
		<link>http://asmeurersympy.wordpress.com/2012/12/30/2012-in-review/</link>
		<comments>http://asmeurersympy.wordpress.com/2012/12/30/2012-in-review/#comments</comments>
		<pubDate>Sun, 30 Dec 2012 23:07:19 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1165</guid>
		<description><![CDATA[The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog. Here&#8217;s an excerpt: 4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 20,000 views in 2012. If each view were a film, this blog would power 5 Film Festivals Click here to see the complete report.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1165&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.</p>
<p>	<a href="http://asmeurersympy.wordpress.com/2012/annual-report/"><img src="http://www.wordpress.com/wp-content/mu-plugins/annual-reports/img/2012-emailteaser.png" width="100%" alt="" /></a></p>
<p>Here&#8217;s an excerpt:</p>
<blockquote><p>4,329 films were submitted to the 2012 Cannes Film Festival. This blog had <strong>20,000</strong> views in 2012. If each view were a film, this blog would power 5 Film Festivals</p></blockquote>
<p><a href="http://asmeurersympy.wordpress.com/2012/annual-report/">Click here to see the complete report.</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1165/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1165/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1165&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2012/12/30/2012-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>

		<media:content url="http://www.wordpress.com/wp-content/mu-plugins/annual-reports/img/2012-emailteaser.png" medium="image" />
	</item>
		<item>
		<title>Infinitely nested lists in Python</title>
		<link>http://asmeurersympy.wordpress.com/2012/09/19/infinitely-nested-lists-in-python/</link>
		<comments>http://asmeurersympy.wordpress.com/2012/09/19/infinitely-nested-lists-in-python/#comments</comments>
		<pubDate>Wed, 19 Sep 2012 04:21:08 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1160</guid>
		<description><![CDATA[Readers of this blog know that I sometimes like to write about some strange, unexpected, and unusual things in Python that I stumble across. This post is another one of those. First, look at this What am I doing here? I&#8217;m creating a list, a, and I&#8217;m adding it to itself. What you end up [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1160&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Readers of this blog know that I sometimes like to write about some <a href="http://asmeurersympy.wordpress.com/2009/07/20/modifying-a-list-while-looping-through-it-in-python/">strange</a>, <a href="http://asmeurersympy.wordpress.com/2010/06/16/strange-python-behavior-can-someone-please-explain-to-me-what-is-going-on-here/">unexpected</a>, and <a href="http://asmeurersympy.wordpress.com/2011/03/15/true-is-true-is-false-is-true-is-false/">unusual</a> things in Python that I stumble across.  This post is another one of those.</p>
<p>First, look at this</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; a = []
&gt;&gt;&gt; a.append(a)
&gt;&gt;&gt; a
[[...]]
</pre>
<p>What am I doing here?  I&#8217;m creating a list, <code>a</code>, and I&#8217;m adding it to itself.  What you end up with is an infinitely nested list.  The first interesting thing about this is that Python is smart enough to not explode when printing this list.  The following should convince you that <code>a</code> does indeed contain itself.</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; a[0] is a
True
&gt;&gt;&gt; a[0] == a
True
</pre>
<p>Now, if you have programmed in C, or a similar language that uses pointers, this should not come as a surprise to you.  Lists in Python, like most things, do not actually contain the items inside them.  Rather, they contain references (in C terminology, &#8220;pointers&#8221;) to the items inside them.  From this perspective, there is no issue at all with <code>a</code> containing a pointer to itself.</p>
<p>The first thing I wondered when I saw this was just how clever the printer was at noticing that the list was infinitely nested.  What if we make the cycle a little more complex?</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; a = []
&gt;&gt;&gt; b = []
&gt;&gt;&gt; a.append(b)
&gt;&gt;&gt; b.append(a)
&gt;&gt;&gt; a
[[[...]]]
&gt;&gt;&gt; b
[[[...]]]
&gt;&gt;&gt; a[0] is b
True
&gt;&gt;&gt; b[0] is a
True
</pre>
<p>So it still works.  I had thought that maybe repr just catches <code>RuntimeError</code> and falls back to printing <code>...</code> when the list is nested too deeply, but it turns out that is not true:</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; a = []
&gt;&gt;&gt; for i in range(10000):
...     a = [a]
... 
&gt;&gt;&gt; a
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
RuntimeError: maximum recursion depth exceeded while getting the repr of a list
</pre>
<p>And by the way, in case you were wondering, it is possible to catch a <code>RuntimeError</code> (using the same <code>a</code> as the previous code block)</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; try:
...     print(a)
... except RuntimeError:
...     print(&quot;no way&quot;)
... 
no way
</pre>
<p>(and you also may notice that this is Python 3. Things behave the same way in Python 2)</p>
<p>Back to infinitely nested lists, we saw that printing works, but there are some things that don&#8217;t work.</p>
<pre class="brush: python; title: ; notranslate">
&gt;&gt;&gt; a[0] == b
True
&gt;&gt;&gt; a[0] == a
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
RuntimeError: maximum recursion depth exceeded in comparison
</pre>
<p><code>a[0] is b</code> holds (i.e., they are exactly the same object in memory), so <code>==</code> is able to short-circuit on them.  But to test <code>a[0] == a</code> it has to recursively compare the elements of <code>a</code> and <code>a[0]</code>.  Since it is infinitely nested, this leads to a recursion error.  Now an interesting question: why does this happen?  Is it because <code>==</code> on lists uses a depth first search?  If it were somehow possible to compare these two objects, would they be equal?</p>
<p>One is reminded of <a href="http://en.wikipedia.org/wiki/Russel%27s_paradox">Russel&#8217;s paradox</a>, and the reason why in <a href="http://en.wikipedia.org/wiki/Zermelo%E2%80%93Fraenkel_set_theory">axiomatic set theory</a>, sets are not allowed to contain themselves. </p>
<p>Thinking of this brought me to my final question.  Is it possible to make a Python <code>set</code> that contains itself?  The answer is obviously no, because <code>set</code> objects can only contain hashable objects, and <code>set</code> is not hashable.  But <code>frozenset</code>, <code>set</code>&#8216;s counterpart, is hashable.  So can you create a <code>frozenset</code> that contains itself?  The same for <code>tuple</code>.  The method I used for <code>a</code> above won&#8217;t work, because <code>a</code> must be mutable to append it to itself.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1160&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2012/09/19/infinitely-nested-lists-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
		<item>
		<title>isympy -I:  A saner interactive environment</title>
		<link>http://asmeurersympy.wordpress.com/2012/08/31/isympy-i-a-saner-interactive-environment/</link>
		<comments>http://asmeurersympy.wordpress.com/2012/08/31/isympy-i-a-saner-interactive-environment/#comments</comments>
		<pubDate>Fri, 31 Aug 2012 03:30:08 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1154</guid>
		<description><![CDATA[As promised, here is another post describing a new feature in the upcoming SymPy 0.7.2. Automatic Symbol Definition While not as ground breaking as the feature I described in my last post, this feature is still quite useful. As you may know, SymPy is inherently a Python library, meaning that it lives by the rules [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1154&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As <a href="http://asmeurersympy.wordpress.com/2012/08/21/sympy-live-sphinx-extension/">promised</a>, here is another post describing a new feature in the upcoming <a href="https://github.com/sympy/sympy/wiki/Release-Notes-for-0.7.2">SymPy 0.7.2</a>.</p>
<h2>Automatic Symbol Definition</h2>
<p>While not as ground breaking as the feature I described in my <a href="http://asmeurersympy.wordpress.com/2012/08/21/sympy-live-sphinx-extension/">last post</a>, this feature is still quite useful. As you may know, SymPy is inherently a Python library, meaning that it lives by the rules of Python. If you want to use any name, whether it be a Symbol or a function (like cos), you need to define it (in the case of Symbols), or import it (in the case of functions that come with SymPy). We provide the script <code>isympy</code> with SymPy to assist with this. This script automatically runs IPython (if it&#8217;s installed), imports all names from sympy (<code>from sympy import *</code>), and defines common symbol names (like <code>x</code>, <code>y</code>, and <code>z</code>).</p>
<p>But if you want to use a Symbol that is not one of the ones predefined by <code>isympy</code>, you will get something like</p>
<pre class="brush: python; title: ; notranslate">
In [1]: r*x
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
 in ()
----&gt; 1 r*x

NameError: name 'r' is not defined
</pre>
<p>The best solution for this has been either to type <code>var('r')</code>, which will create the Symbol <code>r</code> and inject it into the namespace, or to wrap your text in a string and pass it to <code>sympify()</code>, like <code>sympify("r*x")</code>. Neither of these are very friendly in interactive mode.</p>
<p>In SymPy 0.7.2, <code>isympy</code> has a new command line option, <code>isympy -a</code>, which will enable a mechanism that will automatically define all undefined names as Symbols for you:</p>
<pre class="brush: python; title: ; notranslate">
In [1]: r*x
Out[1]: r⋅x
</pre>
<p>There are some caveats to be aware of when using this feature:</p>
<ul>
<li>Names must be undefined for <code>isympy -a</code> to work. If you type something like <code>S*x</code>, you&#8217;ll get:
<pre class="brush: python; title: ; notranslate">
In [3]: S*x
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-3-6656a97ea7b0&gt; in &lt;module&gt;()
----&gt; 1 S*x

TypeError: unsupported operand type(s) for *: 'SingletonRegistry' and 'Symbol'
</pre>
<p>That&#8217;s because <code>S</code> is already defined (it&#8217;s the <code>SingletonRegistry</code>, and also a shortcut to <code>sympify()</code>). To use a name that&#8217;s already defined, either create it manually with <code>var()</code> or delete it using <code>del</code>.</li>
<li>This only works on the top level namespace. If you define a function with an undefined name, it will not automatically define that symbol when run.</li>
<li>This works by catching NameError, defining the name, and then re-running the expression. If you have a multiline statement, any lines before the undefined name will be run before the NameError will be caught. This usually won&#8217;t happen, but it&#8217;s a potential side-effect to be aware of. We plan to rewrite it using either ast or tokenize to avoid this issue.</li>
<li>Obviously, this is intended for interactive use only. If you copy code and put it in a script, or in some other place where someone might be expected to run it, but not necessarily from <code>isympy -a</code>, you should include symbol definitions.</li>
</ul>
<h2>Automatic int to Integer Conversion</h2>
<p>A second thing that is annoying with Python and SymPy is that something like <code>1/2</code> will be interpreted completely by Python, without any SymPy. This means that something like <code>1/2 + x</code> will give either <code>0 + x</code> or <code>0.5 + x</code>, depending on whether or not <code>__future__.division</code> has been imported. <code>isympy</code> has always ran <code>from __future__ import division</code>, so that you&#8217;ll get the latter, but we usually would prefer to get <code>Rational(1, 2)</code>. Previously, the best way to do this was again to either run it through <code>sympify()</code> as a string, or to sympify at least one of the numbers (here the <code>S()</code> shortcut to <code>sympify()</code> is useful, because you can type just <code>S(1)/2</code>).</p>
<p>With SymPy 0.7.2, you can run <code>isympy -i</code>, and it will automatically wrap all integers literals with <code>Integer()</code>. The result is that <code>1/2</code> produces <code>Rational(1, 2)</code>:</p>
<pre class="brush: python; title: ; notranslate">
In [1]: 1/2 + x
Out[1]: x + 1/2
</pre>
<p>Again, there are a couple of caveats:</p>
<ul>
<li>If you want to get Python style division, you just need to wrap both arguments in <code>int()</code>:
<pre class="brush: python; title: ; notranslate">
In [2]: int(1)/int(2)
Out[2]: 0.5
</pre>
<p>Of course, if you just want a floating point number, you can just use <code>N()</code> or <code>.evalf()</code></li>
<li>This works by parsing the text and wrapping all integer literals with <code>Integer()</code>. This means that if you have a variable set to a Python int, it will still act like a Python int:
<pre class="brush: python; title: ; notranslate">
In [6]: a = int(1)

In [7]: b = int(2)

In [8]: a/b
Out[8]: 0.5
</pre>
<p>Note that to even do that example, I had to manually make <code>a</code> and <code>b</code> Python ints by wrapping them in <code>int()</code>. If I had just done <code>a = 1</code>, it would have been parsed as <code>a = Integer(1)</code>, and I would have gotten a SymPy Integer. But this can be an issue if you use the result of some function that returns an int (again, note that most functions in SymPy that return integers return Integer, not int).</li>
<li>The same as before: this will only work interactively. If you want to reuse your code outside of <code>isympy -i</code>, you should take care of any int/int by rewriting it as S(int)/int.</li>
</ul>
<p>Since these are both useful features, we&#8217;ve added a way that you can get them both at once: by doing <code>isympy -I</code> (the &#8220;I&#8221; stands for &#8220;Interactive&#8221;). If we add similar features in the future, we will also add them to the <code>-I</code> shortcut (for example, we may add an option to allow <code>^</code> to automatically be replaced with <code>**</code>).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1154/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1154&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2012/08/31/isympy-i-a-saner-interactive-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
		<item>
		<title>SymPy Live Sphinx Extension</title>
		<link>http://asmeurersympy.wordpress.com/2012/08/21/sympy-live-sphinx-extension/</link>
		<comments>http://asmeurersympy.wordpress.com/2012/08/21/sympy-live-sphinx-extension/#comments</comments>
		<pubDate>Tue, 21 Aug 2012 05:09:13 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1122</guid>
		<description><![CDATA[I didn&#8217;t blog about SymPy all summer, so I thought I would write a post about my favorite feature of the upcoming SymPy 0.7.2 release. &#160;In fact, this feature has got me more excited than any other feature from any version of SymPy. &#160;Yeah, it&#8217;s that good. The feature is the SymPy Live Sphinx extension. [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1122&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I didn&#8217;t blog about SymPy all summer, so I thought I would write a post about my favorite feature of the upcoming SymPy 0.7.2 release. &nbsp;In fact, this feature has got me more excited than any other feature from any version of SymPy. &nbsp;Yeah, it&#8217;s that good.</p>
<p>The feature is the SymPy Live Sphinx extension. &nbsp;To start, if you don&#8217;t know about it, check out <a href="http://live.sympy.org/" target="_blank">SymPy Live</a>. &nbsp;This is a console that runs on the <a href="https://developers.google.com/appengine/">App Engine</a>. &nbsp;We&#8217;ve actually had this for quite some time, but this winter, it got a huge upgrade thanks to the contribution of some <a href="http://www.google-melange.com/gci/homepage/google/gci2011">GCI</a> students. &nbsp;Basically, SymPy Live lets you try out SymPy in your browser completely for free, because it runs all the code on the App Engine. &nbsp;Actually, the console is a full Python console, so you can actually run any valid Python command on it. &nbsp;This past winter, GCI students upgraded the look of the site, added a mobile version (visit live.sympy.org on your phone), and added other neat features like search history and autocompletion.</p>
<p>Now, <a href="http://sphinx.pocoo.org/">Sphinx</a>&nbsp;is the documentation system that we use to generate <a href="http://docs.sympy.org/">SymPy&#8217;s html documentation</a>. Last year, when I was at the&nbsp;<a href="http://asmeurersympy.wordpress.com/2011/07/17/the-scipy-2011-conference/">SciPy Conference</a>, Mateusz had an idea at the sprints to create an extension linking SymPy Live and Sphinx, so that the examples in Sphinx could be easily run in SymPy Live. &nbsp;He didn&#8217;t finish the extension, but I&#8217;m happy to report that thanks to David Li, who was also one of the&nbsp;aforementioned&nbsp;GCI students, the extension is now complete, and is running live on our <a href="http://docs.sympy.org/dev/">development docs</a>. &nbsp;When SymPy 0.7.2 is released (soon I promise), it will be part of the oficial documentation.</p>
<p>The best way to see how awesome this is is to visit the website and check it out. &nbsp;You will need a modern browser (the latest version of Firefox, Safari, or Chrome will work, IE might work too). &nbsp;Go to a page in the development docs with documentation examples, for example,&nbsp;<a href="http://docs.sympy.org/dev/tutorial.html#algebra">http://docs.sympy.org/dev/tutorial.html#algebra</a>, and click on one of the examples (or click on one of the green &#8220;Run code block in SymPy Live&#8221; buttons). You should see a console pop up from the bottom-right of the screen, and run your code. &nbsp;For example:</p>
<div id="attachment_1149" class="wp-caption alignnone" style="width: 460px"><a href="http://asmeurersympy.files.wordpress.com/2012/08/sympy-live-sphinx.png"><img class="size-full wp-image-1149" title="SymPy-Live-Sphinx" src="http://asmeurersympy.files.wordpress.com/2012/08/sympy-live-sphinx.png?w=450&#038;h=317" alt="" width="450" height="317" /></a><p class="wp-caption-text">Example of the SymPy Live Sphinx extension at <a href="http://docs.sympy.org/dev/tutorial.html#algebra">http://docs.sympy.org/dev/tutorial.html#algebra</a>. Click for larger image.</p></div>
<p>&nbsp;</p>
<p>You can access or hide the console at any time by clicking on the green box at the bottom-right of the page. &nbsp;If you click on &#8220;Settings&#8221;, you will see that you can change all the same settings as the regular SymPy Live console, such as the printer type, and the keys for execution and autocompletion. &nbsp;Additionally, there is a new setting, &#8220;Evaluation Mode&#8221;, which changes how the Sphinx examples are evaluated. &nbsp;The default is &#8220;Evaluate&#8221;. &nbsp;In this mode, if you click on an example, it is executed immediately. &nbsp;The other option is &#8220;Copy&#8221;. &nbsp;In this mode, if you click an example, it is copied to the console, but not executed right away. This way, you can edit the code to try something different. &nbsp;Remember, this is a full fledged Python console running SymPy, so you can try literally anything</p>
<p>So play with this and <a href="http://groups.google.com/group/sympy">let us know</a> what you think. &nbsp;We would love to hear ways that we can improve the experience even further. &nbsp;In particular, I think we should think about ways to make the &#8220;Copy&#8221; mode more user-friendly. &nbsp;Suggestions welcome! &nbsp;Also, please <a href="http://code.google.com/p/sympy/issues">report any bugs</a>.</p>
<p>And one word of warning: &nbsp;even though these are the development docs, SymPy Live is still running SymPy 0.7.1. &nbsp;So some examples may not work until 0.7.2 is released, at which point we will update SymPy Live.</p>
<p>I believe that this extension represents the future of interactive documentation.&nbsp;I hope you enjoy.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1122&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2012/08/21/sympy-live-sphinx-extension/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>

		<media:content url="http://asmeurersympy.files.wordpress.com/2012/08/sympy-live-sphinx.png" medium="image">
			<media:title type="html">SymPy-Live-Sphinx</media:title>
		</media:content>
	</item>
		<item>
		<title>Emacs: 7 months later</title>
		<link>http://asmeurersympy.wordpress.com/2012/07/09/emacs-7-months-later/</link>
		<comments>http://asmeurersympy.wordpress.com/2012/07/09/emacs-7-months-later/#comments</comments>
		<pubDate>Mon, 09 Jul 2012 05:24:05 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://asmeurersympy.wordpress.com/?p=1112</guid>
		<description><![CDATA[In my final post about my switching to Emacs, a commenter, Scott, asked me, &#8220;It has been a while since you started using Emacs. I’m just curious. How is your experience so far now that you have more experience and a more complete configuration?&#8221; My reply was getting quite long, so I figured it would [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1112&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In my <a href="http://asmeurersympy.wordpress.com/2012/01/13/vim-vs-emacs-part-3/">final post</a> about my switching to Emacs, a <a href="http://asmeurersympy.wordpress.com/2012/01/13/vim-vs-emacs-part-3/#comment-544">commenter</a>, Scott, asked me, &#8220;It has been a while since you started using Emacs. I’m just curious. How is your experience so far now that you have more experience and a more complete configuration?&#8221;  My reply was getting quite long, so I figured it would be best suited as a new post.</p>
<p>The short answer is, mostly the same since I wrote that <a href="http://asmeurersympy.wordpress.com/2012/01/13/vim-vs-emacs-part-3">Vim vs. Emacs (part 3)</a>. Once you use something a lot, you notice all kinds of things that could use improvements. Some of them are just minor annoyances. For example, many interactive commands in Emacs (but not all!) require you to type out &#8220;yes&#8221; instead of just &#8220;y&#8221; as a confirmation. Others are more serious, like the need for a real replacement of SuperTab from vim.</p>
<p>I actually didn&#8217;t have much free time to work on configuring Emacs during the school year, and once the summer started, my computer died, and I&#8217;ve been working of an old laptop running Linux until I can get a new one. Fortunately, I had the foresight to put all my Emacs configuration <a href="https://github.com/asmeurer/dotfiles">online on GitHub</a>, so it was easy to get my configuration again. I&#8217;ve noticed that in Linux, the Alt key (i.e., Meta) is used for other things, so it doesn&#8217;t work so well in Emacs (e.g., pressing Alt without any other keys sometimes activates a menu that removes the keyboard focus, and also C-M shortcuts don&#8217;t seem to work at all).</p>
<p>I&#8217;ve memorized very few keyboard shortcuts, even ones that might be useful to me (e.g., I don&#8217;t remember the shortcut to jump to a matching parenthesis). Usually, if I am using some mode or something and I want to know how to do something, I just Google it, and generally find the answer within a few seconds.</p>
<p>There are several major configuration issues that I&#8217;ve yet to address, either due to lack of time or because I couldn&#8217;t find a suitable solution. A SuperTab replacement is one.  This is actually a big one, because scrolling through a file just to see what&#8217;s there is getting older and older, as is searching just to jump to a function definition.  If anyone knows of a good way to do this, please let me know.  I mainly need it for Python files, but having it other modes as well would be nice.  Basically, I just want something that shows me all the class and function definitions in the file, in order, that I can easily select one and jump to it.</p>
<p>Related to searching, searching in Emacs sucks. I&#8217;m using isearch+, which is an improvement, but it still bugs me that search does not wrap around by default. Also, for some reason, pressing delete doesn&#8217;t delete the last character you typed, but the last character that it matched. That may sound minor, but I use it a lot, so it&#8217;s really gotten on my nerves.</p>
<p>Regular expression searching in Emacs is useless.  I can never get it to work (usually because of differences between () and \(\)).  What I really want is an interactive, user friendly, regular expression search/search and replace tool.  There&#8217;s regexp-builder, but that&#8217;s useless because once you build the regular expression, you have to manually copy it and paste it into the real regular expression search function to actually use it.  And it doesn&#8217;t work with search and replace.</p>
<p>This last semester I had a semester long project in C.  For that, flymake-mode was a godsend.  It requires a bit of manual configuration (you have to add something to your Makefile, and you have to add some stuff to .emacs as always to enable it by default), but once you do that, it just works.  If you don&#8217;t know what this is, basically, it highlights the compiler errors in your source in real time, as you type it.  So instead of doing something stupid twenty times, and then compiling and finding them all, you do something stupid once, see the error, and don&#8217;t do make the mistake any more.  It&#8217;s also nice to close your editor and know that your code will compile.</p>
<p>The Python mode I am mixed about.  On the one hand, it&#8217;s really awesome how smart it is about indentation.  On the other hand, the syntax highlighting is just shy of what I want (granted, it&#8217;s pretty good, but I want better than that).  For example, I want to be able to color docstrings, single quoted strings, and double quoted strings differently.  It would also be awesome to get some coloring in docstrings itself.  I&#8217;m thinking markdown mode for any text that&#8217;s in a docstring, except for doctests, which are colored in Python mode (or some variant).</p>
<p>Some things I&#8217;ve not really cared much about yet because I haven&#8217;t used that type of file yet.  For example, I&#8217;m currently writing this post in Emacs, and just now noticing the deficiencies in html-mode (e.g., I want an easy way to select text and turn it into a link, just like in the WordPress editor).</p>
<p>Finally, I&#8217;ve been trying to write my own theme.  That process has been slow and slightly painful.  Emacs is currently in the process of moving to themes, though, so this is to be expected.  When Emacs 24 is actually released I think it will be fair to judge how well this feature works.</p>
<p>That&#8217;s my wishlist (or most of it anyway).  But there are positive things too. auto-complete-mode, which I mentioned at the top of my previous blog post, is absolutely awesome.  I think this extension alone has made me more productive.</p>
<p>Some things I take for granted, like automatic spell checking of strings and comments in Python (not enabled by default, but not hard to configure either).  Thanks to someone on an Emacs mailing list, I have the perfect automatic clearing of trailing whitespace, that automatically leaves your whitespace before the cursor in the buffer, but still writes the clear to the file (see my .emacs file from my dotfiles repo linked to above for details).</p>
<p>I&#8217;ve been hoping to learn Emacs lisp, so that I could remedy many of these problems on my own, but so far I haven&#8217;t really had the free time.  Lisp is a very confusing language, so it&#8217;s not easy to jump into (compared to the language vim uses, which I found easy enough to hack on without knowing at all).</p>
<p>Ultimately, I&#8217;m quite pleased with how user friendly Emacs is, and with how easy it is to find out how to do almost anything I want just by Googling it. Configuration is an uphill battle.  Emacs has a ton of great packages, many of which are included, but almost none are enabled by default.  Just today I discovered Ido mode, thanks to <a href="http://asmeurersympy.wordpress.com/2012/01/13/vim-vs-emacs-part-3/#comment-543"> David Li</a>.  I feel that in the long term, as I learn Emacs Lisp, I can make it do whatever I want.  It provides a good baseline editing experience, and a good framework for configuring it to do whatever you want, and also enough people use it that 99% of the things you want are already done by somebody.</p>
<p><!-- LocalWords:  SuperTab isearch flymake Makefile WordPress repo --></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1112/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1112/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1112&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2012/07/09/emacs-7-months-later/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
		<item>
		<title>How to install the development version of IPython Qtconsole and Notebook in Ubuntu</title>
		<link>http://asmeurersympy.wordpress.com/2012/06/14/how-to-install-the-development-version-of-ipython-qtconsole-and-notebook-in-ubuntu/</link>
		<comments>http://asmeurersympy.wordpress.com/2012/06/14/how-to-install-the-development-version-of-ipython-qtconsole-and-notebook-in-ubuntu/#comments</comments>
		<pubDate>Thu, 14 Jun 2012 05:49:08 +0000</pubDate>
		<dc:creator>Aaron Meurer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://asmeurersympy.wordpress.com/?p=1109</guid>
		<description><![CDATA[Both the awesome IPython notebook and Qtconsole are in the Ubuntu repositories, so if you just want to use the stable released versions, you can just do and be on your way. But the git development version has a lot of cool new features, and you may not want to wait for 0.13 to be [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1109&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Both the awesome <a href="http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html">IPython notebook</a> and <a href="http://ipython.org/ipython-doc/stable/interactive/qtconsole.html">Qtconsole</a> are in the Ubuntu repositories, so if you just want to use the stable released versions, you can just do</p>
<pre class="brush: bash; title: ; notranslate">
sudo apt-get install ipython-notebook ipython-qtconsole
</pre>
<p>and be on your way.  But the git development version has a lot of cool new features, and you may not want to wait for 0.13 to be released and make its way to the Ubuntu repos.  But you may be thinking that to use those you will have to figure out all the dependencies yourself.  Actually, it&#8217;s pretty easy:</p>
<pre class="brush: bash; title: ; notranslate">
# First install git, if you don't already have it
sudo apt-get install git
# Then, clone the IPython repo, if you haven't already.
git clone git://github.com/ipython/ipython.git
cd ipython
# Now just install IPython with apt, then uninstall it.  The dependencies will remain
sudo apt-get install ipython-notebook ipython-qtconsole
sudo apt-get remove ipython-notebook ipython -qtconsole ipython
# Now install the IPython git version in such a way that will keep up to date when you pull
sudo python setup.py develop
</pre>
<p>To update, just cd into that ipython directory and type <code>git pull</code>.  That&#8217;s it.  Now type <code>ipython notebook</code> or <code>ipython qtconsole</code> to get the magic.</p>
<p>EDIT: After you do this, <code>apt-get</code> will start bugging you every time that you use it that a bunch of packages are no longer needed.  These are the ones that you do need for the qtconsole and the notebook, so you should not autoremove them as it says.  Rather, set them as manually installed by copying the list of packages that it tells you about and <code>sudo apt-get install</code>ing them.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/asmeurersympy.wordpress.com/1109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/asmeurersympy.wordpress.com/1109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=asmeurersympy.wordpress.com&#038;blog=7467151&#038;post=1109&#038;subd=asmeurersympy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://asmeurersympy.wordpress.com/2012/06/14/how-to-install-the-development-version-of-ipython-qtconsole-and-notebook-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0383e4cae325f65a1bbd906be4be2276?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">asmeurer</media:title>
		</media:content>
	</item>
	</channel>
</rss>
