<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Matthew Leingang</title>
<link>https://www.matthewleingang.com/blog/</link>
<atom:link href="https://www.matthewleingang.com/blog/index.xml" rel="self" type="application/rss+xml"/>
<description>Mathematics educator and academic leader: teaching, teacher training, and educational technology.</description>
<image>
<url>https://www.matthewleingang.com/images/social-card.png</url>
<title>Matthew Leingang</title>
<link>https://www.matthewleingang.com/blog/</link>
<height>75</height>
<width>144</width>
</image>
<generator>quarto-1.11.9</generator>
<lastBuildDate>Mon, 30 Nov 2026 00:00:00 GMT</lastBuildDate>
<item>
  <title>A vortex that doesn’t rotate</title>
  <link>https://www.matthewleingang.com/blog/posts/2026-11-30-a-vortex-that-doesnt-rotate/</link>
  <description><![CDATA[ 





<p>In 2017, Math Stack Exchange user <a href="https://math.stackexchange.com/users/179404/rax-adaam">Rax Adaam</a> asked about the textbook example <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%7BF%7D(x,y)%20=%20%5Cleft%3C%20%5Cfrac%7B-y%7D%7Bx%5E2+y%5E2%7D,%5C,%20%5Cfrac%7Bx%7D%7Bx%5E2+y%5E2%7D%20%5Cright%3E.%0A"> Every textbook says it is not conservative. But <img src="https://latex.codecogs.com/png.latex?%5Cphi(x,y)%20=%20%5Carctan(y/x)"> satisfies <img src="https://latex.codecogs.com/png.latex?%5Cnabla%5Cphi%20=%20%5Cmathbf%7BF%7D">. So what does “conservative” actually mean? <a href="../../../blog/answers/2017-10-20-math-why-is-this-vector-field-not-conservative-even-though-it-has/">My answer</a> (<a href="https://math.stackexchange.com/questions/2481593/why-is-this-vector-field-not-conservative-even-though-it-has-a-potential-what/2481600#2481600">original on Math.SE</a>) was that a potential has to have the same domain as the field, and <img src="https://latex.codecogs.com/png.latex?%5Carctan(y/x)"> doesn’t.</p>
<p>I wrote <a href="../../../blog/posts/2026-11-28-visualizing-nonconservative-vector-fields/">Visualizing nonconservative vector fields</a> to include a visualization of conservative and non-conservative plane vector fields and their effect on objects. That post had a field with no visible circles that nevertheless rotates. This one has the opposite: a field that is all circles, but doesn’t rotate.</p>
<section id="revolution-without-rotation" class="level2">
<h2 class="anchored" data-anchor-id="revolution-without-rotation">Revolution without rotation</h2>
<p>The arrows of <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> circle the origin counterclockwise, getting shorter as you move out. (Its length is <img src="https://latex.codecogs.com/png.latex?1/r">, where <img src="https://latex.codecogs.com/png.latex?r%20=%20%5Csqrt%7Bx%5E2+y%5E2%7D">.) Yet with <img src="https://latex.codecogs.com/png.latex?P%20=%20-y/r%5E2"> and <img src="https://latex.codecogs.com/png.latex?Q%20=%20x/r%5E2">, <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D%20=%20%5Cfrac%7By%5E2%20-%20x%5E2%7D%7B(x%5E2+y%5E2)%5E2%7D%0A=%20%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D,%0A"> so the scalar curl <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D%20-%20%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D"> is zero at every point where <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> is defined.</p>
<p>Here is physical demonstration. The wheel below is carried by the flow, and its spin is measured from how the flow pushes on its rim, the same way as in the earlier demo. Watch the highlighted spoke.</p>
<div id="vortex-demo" class="my-3"></div>
<script src="vortex-demo.js"></script>
<p>The wheel orbits the origin, but the highlighted spoke keeps pointing up, the way a compass needle would. Now switch the menu to <img src="https://latex.codecogs.com/png.latex?%5Cleft%3C%20-y,%20x%20%5Cright%3E">, which is rigid rotation: the whole plane turning like a record. There the wheel orbits <em>and</em> turns, once per orbit, always showing the same face to the origin, like the Moon. Its curl is <img src="https://latex.codecogs.com/png.latex?2">, and the wheel spins with a rate of half that: <img src="https://latex.codecogs.com/png.latex?%5Comega%20=%201">.</p>
<p>Why the difference? Two effects compete on a wheel going around in a circular flow:</p>
<ul>
<li>Being carried around a circle turns the wheel counterclockwise, just as with the Moon.</li>
<li>If the flow is faster on the inside of the wheel than on the outside, that shear turns the wheel clockwise.</li>
</ul>
<p>In rigid rotation the speed is <img src="https://latex.codecogs.com/png.latex?r">, so the outside is <em>faster</em> and nothing cancels the first effect. In <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> the speed is <img src="https://latex.codecogs.com/png.latex?1/r">, so the inside is faster, and the two effects cancel exactly. In fact, for a circular flow with speed <img src="https://latex.codecogs.com/png.latex?v(r)">, the curl is <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bv%7D%7Br%7D%20+%20%5Cfrac%7Bdv%7D%7Bdr%7D%20=%20%5Cfrac%7B1%7D%7Br%7D%5Cfrac%7Bd%7D%7Bdr%7D%5Cbigl(r%5C,v(r)%5Cbigr),%0A"> which is zero exactly when <img src="https://latex.codecogs.com/png.latex?r%5C,v(r)"> is constant. So <img src="https://latex.codecogs.com/png.latex?v%20=%20c/r"> is the <em>only</em> circular flow that doesn’t rotate. Fluid dynamicists call it an <a href="https://en.wikipedia.org/wiki/Vortex#Irrotational_vortices">irrotational vortex</a>; it is the textbook model of water swirling down a drain.</p>
</section>
<section id="still-not-conservative" class="level2">
<h2 class="anchored" data-anchor-id="still-not-conservative">Still not conservative</h2>
<p>Irrotationality is a sufficient but not a necessary condition for a vector field to be conservative. If <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D%20=%20%5Cnabla%5Cphi"> on its whole domain, then the work done by <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> along a path is <img src="https://latex.codecogs.com/png.latex?%5Cphi(%5Ctext%7Bend%7D)%20-%20%5Cphi(%5Ctext%7Bstart%7D)">, so the work around any closed loop is zero. For <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> that fails on the unit circle <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Br%7D(t)%20=%20%5Cleft%3C%20%5Ccos%20t,%20%5Csin%20t%20%5Cright%3E">: <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%7BF%7D(%5Cmathbf%7Br%7D(t))%5Ccdot%5Cmathbf%7Br%7D'(t)%0A=%20%5Cleft%3C%20-%5Csin%20t,%20%5Ccos%20t%20%5Cright%3E%20%5Ccdot%20%5Cleft%3C%20-%5Csin%20t,%20%5Ccos%20t%20%5Cright%3E%20=%201,%0A%5Cqquad%0A%5Coint%20%5Cmathbf%7BF%7D%5Ccdot%20d%5Cmathbf%7Br%7D%20=%20%5Cint_0%5E%7B2%5Cpi%7D%201%5C,dt%20=%202%5Cpi.%0A"></p>
<p>The demo keeps a running total of the work done along the wheel’s path. Drop the wheel anywhere and let it go around once: it comes back to where it started, yet the work has gone up by <img src="https://latex.codecogs.com/png.latex?2%5Cpi%20%5Capprox%206.28">. Every lap adds another <img src="https://latex.codecogs.com/png.latex?2%5Cpi">, no matter how big the orbit is. (In rigid rotation the work also keeps growing, but that field isn’t even irrotational, so that is no surprise.)</p>
</section>
<section id="so-where-did-the-potential-go" class="level2">
<h2 class="anchored" data-anchor-id="so-where-did-the-potential-go">So where did the potential go?</h2>
<p>Turn on the level curves of <img src="https://latex.codecogs.com/png.latex?%5Carctan(y/x)">. They are rays from the origin, and <img src="https://latex.codecogs.com/png.latex?%5Carctan(y/x)"> does what a potential should: as the wheel moves, the work done equals the change in <img src="https://latex.codecogs.com/png.latex?%5Carctan(y/x)">. Until the wheel crosses the dashed line. There, on the <img src="https://latex.codecogs.com/png.latex?y">-axis, <img src="https://latex.codecogs.com/png.latex?%5Carctan(y/x)"> isn’t defined, and on the far side its value has jumped by <img src="https://latex.codecogs.com/png.latex?%5Cpi"> while the work went on smoothly.</p>
<p>That’s what my answer meant. <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20%5Carctan(y/x)%20=%20%5Cmathbf%7BF%7D">, but only on the plane minus the <img src="https://latex.codecogs.com/png.latex?y">-axis. <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> is defined on the plane minus only the origin, and on that bigger domain nothing works.</p>
<p>You can do better than <img src="https://latex.codecogs.com/png.latex?%5Carctan(y/x)">. The polar angle <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> is a potential on the plane minus <em>one</em> ray from the origin. Some math programming libraries have an <a href="https://en.wikipedia.org/wiki/Atan2"><code>atan2</code> function</a>, which takes a point <img src="https://latex.codecogs.com/png.latex?(x,y)"> in the plane and returns an angle <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> such that <img src="https://latex.codecogs.com/png.latex?%5Ccos%5Ctheta%20=%20%5Cfrac%7Bx%7D%7B%5Csqrt%7Bx%5E2+y%5E2%7D%7D"> and <img src="https://latex.codecogs.com/png.latex?%5Csin%5Ctheta=%5Cfrac%7By%7D%7B%5Csqrt%7Bx%5E2+y%5E2%7D%7D">.</p>
<p>But it can’t be extended any further: going once around the origin increases <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> by <img src="https://latex.codecogs.com/png.latex?2%5Cpi">, so a function defined all the way around would need two values at the same point. The <code>atan2</code> function cannot be continuous. Usually it is defined to overlap with <img src="https://latex.codecogs.com/png.latex?%5Carctan(y/x)"> when <img src="https://latex.codecogs.com/png.latex?x%20%3E%200">, so that it’s discontinuous along the negative <img src="https://latex.codecogs.com/png.latex?x">-axis, and has image <img src="https://latex.codecogs.com/png.latex?-%5Cpi%20%3C%20%5Ctheta%20%5Cleq%20%5Cpi">.</p>
<p>The work tally in the demo is really just <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> unwound: it is exactly <img src="https://latex.codecogs.com/png.latex?2%5Cpi"> times the number of laps.</p>
<p>So the answer to “is <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> conservative?” depends on the domain:</p>
<ul>
<li>On any region that doesn’t wrap around the origin (a half-plane, a disk that misses the origin, the plane minus a ray), <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> is conservative. All of these are simply connected, which is the additional hypothesis the textbooks attach to <a href="../../../blog/answers/2017-04-25-math-determining-whether-a-vector-field-is-conservative/">“zero curl implies conservative.”</a></li>
<li>On the punctured plane, which isn’t simply connected, it isn’t.</li>
</ul>
</section>
<section id="eschers-staircase" class="level2">
<h2 class="anchored" data-anchor-id="eschers-staircase">Escher’s staircase</h2>
<p>You may have seen M. C. Escher’s 1960 lithograph <a href="https://en.wikipedia.org/wiki/Ascending_and_Descending"><em>Ascending and Descending</em></a> (you can often find it on the dorm room wall of a college math major, yours truly included). On the roof of a monastery, a staircase runs around a courtyard. One line of monks climbs it forever, and another descends it forever, yet both keep coming back to where they started. Escher based it on the <a href="https://en.wikipedia.org/wiki/Penrose_stairs">Penrose stairs</a> of Lionel and Roger Penrose.</p>
<p>The staircase and <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> have the same kind of impossibility. Think of a potential as a height, so that the work <img src="https://latex.codecogs.com/png.latex?%5Cint%20%5Cmathbf%7BF%7D%5Ccdot%20d%5Cmathbf%7Br%7D"> is the height you gain along a path. Cover any small piece of the staircase with your hand, and what’s left is an ordinary flight of stairs: every step is a consistent height above its neighbors. That is zero curl: near every point <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> has a potential, and the rays in the demo are its stair treads. Walking counterclockwise around the origin you cross them going up, like the climbing monks; walking clockwise you go down.</p>
<p>The trouble only shows when you go all the way around. You have climbed <img src="https://latex.codecogs.com/png.latex?2%5Cpi"> and arrived where you started, so there is no single height function for the whole staircase. Escher’s drawing has no visible seam where the heights stop matching up, because there isn’t one: any place you choose to cut it is as good as any other. That is just like <img src="https://latex.codecogs.com/png.latex?%5Ctheta">, which works on the plane minus <em>any</em> ray. Roger Penrose later made the connection precise in “On the cohomology of impossible figures” (<em>Leonardo</em> 25, 1992): the impossibility of a figure like this is measured by a cohomology class, and <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> is the standard example of a nonzero one, a field that is <em>closed</em> (curl zero) but not <em>exact</em> (not a gradient). Turned around, fields like this are a way to detect holes: if a domain carries a field with zero curl that isn’t conservative, the domain can’t be simply connected. I made that point in <a href="../../../blog/answers/2017-05-11-math-why-cant-all-vector-functions-not-be-gradient-of-a-scalar-fu/">another old answer</a>, which also uses <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> as its counterexample.</p>
</section>
<section id="the-physicists-way-out" class="level2">
<h2 class="anchored" data-anchor-id="the-physicists-way-out">The physicist’s way out</h2>
<p>There’s still a puzzle. The curl is zero everywhere <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> is defined, and yet the circulation around the unit circle is <img src="https://latex.codecogs.com/png.latex?2%5Cpi">. Green’s theorem says the circulation around a loop equals the total curl inside it. So all of it must be hiding at the origin, the one point where <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> isn’t defined. (Physicists write <img src="https://latex.codecogs.com/png.latex?%5Coperatorname%7Bcurl%7D%5Cmathbf%7BF%7D%20=%202%5Cpi%5C,%5Cdelta">.) Any loop around the origin picks up the same <img src="https://latex.codecogs.com/png.latex?2%5Cpi"> (try it with different orbits), and any loop that doesn’t go around it picks up nothing.</p>
<p>To see it, check <em>Pin the axle</em>. Now the wheel is fixed in place, like a paddle wheel on a post, and only spins. Click anywhere away from the origin and it stays still. Click on the origin itself so that the rim surrounds it, and it spins counterclockwise. The demo’s spin is the circulation around the rim divided by <img src="https://latex.codecogs.com/png.latex?2%5Cpi%20R%5E2"> (twice the wheel’s area), so here it is <img src="https://latex.codecogs.com/png.latex?1/R%5E2%20%5Capprox%204.94"> for the wheel’s radius <img src="https://latex.codecogs.com/png.latex?R%20=%200.45">. That’s the whole vortex, concentrated in a single point.</p>


</section>

 ]]></description>
  <category>math</category>
  <category>vector-calculus</category>
  <guid>https://www.matthewleingang.com/blog/posts/2026-11-30-a-vortex-that-doesnt-rotate/</guid>
  <pubDate>Mon, 30 Nov 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Visualizing nonconservative vector fields</title>
  <link>https://www.matthewleingang.com/blog/posts/2026-11-28-visualizing-nonconservative-vector-fields/</link>
  <description><![CDATA[ 





<p>Earlier this month, Math Stack Exchange user <a href="https://math.stackexchange.com/users/1781165/kolkatas">Kolkatas</a> asked why the vector field <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D(x,y)=%5Cleft%3C%20y,0%20%5Cright%3E"> is not conservative. Its plot shows nothing but horizontal arrows pointing to the right, so “there is no circle,” and yet <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D%20%5Cneq%20%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D">. <a href="../../../blog/answers/2026-11-17-math-why-vector-field-fx-y-y-0-is-not-conservative/">My answer</a> (<a href="https://math.stackexchange.com/questions/5154532/why-vector-field-fx-y-y-0-is-not-conservative/5154540#5154540">original on Math.SE</a>) gave the short version. Here is the longer one, with a demo applet.</p>
<p>Kolkatas is correct that the irrotationality condition <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D%20=%20%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D"> is necessary for the vector field to be conservative. And for this vector field, <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D%20=%201"> while <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D%20=%200">. So it is not conservative.</p>
<p>But Kolkatas is incorrect that one should be able to see circles in nonconservative field. Here is a plot of the vector field. All the vectors are horizontal, so no “circles” are visible.</p>
<div id="flow-demo" class="my-3"></div>
<script src="flow-demo.js"></script>
<p>But if you drop a wheel in the plane and let it move according to the flow, you see the wheel both moves and rotates. In the upper half-plane, the “top” of the wheel has a longer vector emanating from it, which means that point moves faster. At the “bottom” of the wheel, the vector is pushing in the same direction but not as strong. The result is that the wheel is pushed to the right, but also rotates clockwise slightly.</p>
<p>This type of nonconservative motion is called <em>shearing</em>. In a <a href="https://en.wikipedia.org/wiki/Shear_mapping">shear transformation</a>, points are displaced in a single direction by an amount proportional to their distance from a fixed line in that direction. It’s not hard to see that in a coordinate system where that “fixed line” is the <img src="https://latex.codecogs.com/png.latex?x">-axis, the vector field associated with such a transformation would have components similar to <img src="https://latex.codecogs.com/png.latex?%5Cleft%3C%20y,%200%20%5Cright%3E">. A square placed in the vector field would be stretched in the horizontal direction, as one side moves faster than the other.</p>
<p>But you can still find the circles. Notice <img src="https://latex.codecogs.com/png.latex?%20%5Cleft%3C%20y,%200%20%5Cright%3E%0A=%20%5Cleft%3C%20%5Cfrac%7By%7D%7B2%7D,%5Cfrac%7Bx%7D%7B2%7D%5Cright%3E%20+%20%5Cleft%3C%20%5Cfrac%7By%7D%7B2%7D,-%5Cfrac%7Bx%7D%7B2%7D%5Cright%3E%0A=%20%5Cnabla%5Cleft(%5Cfrac%7Bxy%7D%7B2%7D%5Cright)+%20%5Cleft%3C%20%5Cfrac%7By%7D%7B2%7D,-%5Cfrac%7Bx%7D%7B2%7D%5Cright%3E%0A"> The first term is a gradient vector field, and the second is purely rotational. You can isolate each of these and see that the first exhibits no rotation (but lots of stretching), while the second induces circular motion around the origin.</p>
<p>If we add a third component equal to zero, we can see the complete <a href="https://en.wikipedia.org/wiki/Helmholtz_decomposition">Helmholtz decomposition</a> of <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D">: <img src="https://latex.codecogs.com/png.latex?%20%5Cleft%3C%20y,%200,%200%20%5Cright%3E%0A=%20%5Cnabla%5Cleft(%5Cfrac%7Bxy%7D%7B2%7D%5Cright)%0A+%20%5Cnabla%20%5Ctimes%20%5Cleft%3C%200,0,%5Cfrac%7B1%7D%7B4%7D(x%5E2+y%5E2)%20%5Cright%3E%0A"> The irrotational component is the gradient of a function, and the rotational component is the curl of a vector field.</p>



 ]]></description>
  <category>math</category>
  <category>vector-calculus</category>
  <guid>https://www.matthewleingang.com/blog/posts/2026-11-28-visualizing-nonconservative-vector-fields/</guid>
  <pubDate>Sat, 28 Nov 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Beamer overlays on TikZ nodes, revisited</title>
  <link>https://www.matthewleingang.com/blog/posts/2026-11-23-beamer-overlays-tikz-revisited/</link>
  <description><![CDATA[ 





<!-- DRAFT written with Claude. Check the TODO comments, and put the history in
     your own words. Publish this together with the 2010 answer, which links here. -->
<p>In 2010 someone asked on TeX Stack Exchange how to highlight a TikZ node on a later beamer slide, the way <code>&lt;alert@2&gt;</code> highlights an item in a list. <a href="../../../blog/answers/2010-11-29-tex-how-to-make-beamer-overlays-with-tikz-node/">My answer</a> (<a href="https://tex.stackexchange.com/questions/6135/how-to-make-beamer-overlays-with-tikz-node/6155#6155">original on TeX.SE</a>) defined a TikZ key that takes a beamer overlay specification as one of its arguments:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode latex code-with-copy"><code class="sourceCode latex"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\tikzset</span>{onslide/.code args={&lt;#1&gt;#2}{<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span></span>
<span id="cb1-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\only</span>&lt;#1&gt;{<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\pgfkeysalso</span>{#2}} <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% \pgfkeysalso doesn't change the path</span></span>
<span id="cb1-3">}}</span></code></pre></div></div>
<p>so that <code>onslide=&lt;3-&gt;{red}</code> makes a node red from slide 3 on.</p>
<p>That idea, along with its explanatory comment, was picked up and extended. As the answer grew in upvotes, I realized that it would make a good package for CTAN. But it languished on my “SOMEDAY: Summer” to-do list for years.</p>
<p>When I finally got around to it, I realized I didn’t have to. The <a href="https://ctan.org/pkg/aobs-tikz"><code>aobs-tikz</code></a> package by Claudio Fiandrino provides a TikZ library, <code>overlay-beamer-styles</code>, which in turn provides several keys with beamer overlay specifications as arguments. The documentation describes the implementation as building on an <a href="https://tex.stackexchange.com/a/55849/1402">answer by TeX.SE user Daniel</a>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode latex code-with-copy"><code class="sourceCode latex"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\tikzset</span>{</span>
<span id="cb2-2">    invisible/.style={opacity=0},</span>
<span id="cb2-3">    visible on/.style={alt={#1{}{invisible}}},</span>
<span id="cb2-4">    alt/.code args={&lt;#1&gt;#2#3}{<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span></span>
<span id="cb2-5">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\alt</span>&lt;#1&gt;{<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\pgfkeysalso</span>{#2}}{<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\pgfkeysalso</span>{#3}} <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% \pgfkeysalso doesn't change the path</span></span>
<span id="cb2-6">    },</span>
<span id="cb2-7">  }</span></code></pre></div></div>
<p>The <code>alt</code> key expects three arguments. The first is a beamer overlay specification to feed to <code>\alt</code>. The next two are the key/values to be set in case the overlay specification is or is not active. The <code>invisible</code> style uses opacity to make the rest of the TikZ path invisible. Then <code>visible on</code> takes an overlay specification (including the angle brackets) and sets the <code>invisible</code> style when that specification is not active.</p>
<p>I recognized my comment and asked Claudio if he would mind acknowledging my original answer along with Daniel’s innovation.</p>
<p>Now in 2026, my beamer slide decks make frequent use of this library instead of my hand-rolled solution. This one line of TikZ code is probably among the greatest-impact contributions in my academic career.</p>
<section id="the-same-frame-today" class="level2">
<h2 class="anchored" data-anchor-id="the-same-frame-today">The same frame, today</h2>
<p>Here is the example from the original answer, using the <code>overlay-beamer-styles</code> library instead. It also addresses another annoyance: different TikZ styles might change the node size, which can complicate relative positioning.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode latex code-with-copy"><code class="sourceCode latex"><span id="cb3-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">\documentclass</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">beamer</span>}</span>
<span id="cb3-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">\usepackage</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">tikz</span>}</span>
<span id="cb3-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\usetikzlibrary</span>{overlay-beamer-styles, positioning}</span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\tikzset</span>{</span>
<span id="cb3-6">  highlight/.style={red, ultra thick},</span>
<span id="cb3-7">  system/.style={</span>
<span id="cb3-8">    draw, rectangle, rounded corners=3pt,</span>
<span id="cb3-9">    minimum width=2cm, text width=1.8cm, align=center,</span>
<span id="cb3-10">    outer sep=1pt, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% fixed, so thick borders don't move the anchors</span></span>
<span id="cb3-11">  },</span>
<span id="cb3-12">}</span>
<span id="cb3-13"></span>
<span id="cb3-14"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">\begin</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">document</span>}</span>
<span id="cb3-15"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">\begin</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">frame</span>}</span>
<span id="cb3-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\centering</span></span>
<span id="cb3-17">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">\begin</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">tikzpicture</span>}[node distance=2.4cm and 3cm, on grid]</span>
<span id="cb3-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\node</span> [system, alt=&lt;3-&gt;{highlight}{}] (fe) {Feature Extraction};</span>
<span id="cb3-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\node</span> [system, alt={&lt;2,4&gt;{green}{}}, right=of fe]</span>
<span id="cb3-20">      (am) {Acoustic Model};</span>
<span id="cb3-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\node</span> [system, right=of am,</span>
<span id="cb3-22">           alt=&lt;-2&gt;{blue}{}, alt=&lt;3&gt;{highlight}{}, alt=&lt;4&gt;{green}{}]</span>
<span id="cb3-23">      (lm) {Language Model};</span>
<span id="cb3-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\node</span> [system, below=of lm] (d) {Decoder};</span>
<span id="cb3-25"></span>
<span id="cb3-26">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\draw</span> [-&gt;] (fe) -- (am);</span>
<span id="cb3-27">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\draw</span> [-&gt;] (am) |- (d);</span>
<span id="cb3-28">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\draw</span> [-&gt;] (lm) -- (d);</span>
<span id="cb3-29"></span>
<span id="cb3-30">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% pin the bounding box, so beamer doesn't re-center a picture</span></span>
<span id="cb3-31">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">% that grew because of a thick border</span></span>
<span id="cb3-32">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\pgfresetboundingbox</span></span>
<span id="cb3-33">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">\useasboundingbox</span> (fe.north west) rectangle (lm.east |- d.south);</span>
<span id="cb3-34">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">\end</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">tikzpicture</span>}</span>
<span id="cb3-35"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">\end</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">frame</span>}</span>
<span id="cb3-36"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">\end</span>{<span class="ex" style="color: null;
background-color: null;
font-style: inherit;">document</span>}</span></code></pre></div></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.matthewleingang.com/blog/posts/2026-11-23-beamer-overlays-tikz-revisited/overlays.gif" class="img-fluid figure-img" alt="Animation cycling through four beamer slides of a block diagram (Feature Extraction, Acoustic Model, Language Model, Decoder). Slide 1: Language Model is blue. Slide 2: Acoustic Model turns green. Slide 3: Feature Extraction and Language Model are thick and red. Slide 4: Feature Extraction stays red; Acoustic Model and Language Model are green. The boxes stay in exactly the same place on every slide."></p>
<figcaption>The four overlays, one per second. Unlike the 2010 version, nothing shifts between slides.</figcaption>
</figure>
</div>
<p>The library’s <code>alt=&lt;spec&gt;{keys}{other keys}</code> applies <code>keys</code> on the slides in <code>spec</code> and <code>other keys</code> everywhere else. It covers both of the keys I defined in 2010: <code>onslide=&lt;3-&gt;{highlight}</code> becomes <code>alt=&lt;3-&gt;{highlight}{}</code>, and my three-way <code>temporal</code> key becomes three <code>alt</code>s. In addition to <code>visible on=&lt;spec&gt;</code>, which reveals an element without moving anything else, the library provides keys like <code>fill on</code>, <code>draw on</code>, and <code>text on</code> for switching between a normal and a “background” style.</p>
<p>The comma quirk is still there, though. An overlay specification with a comma, like <code>&lt;2,4&gt;</code>, requires all three arguments to be wrapped in braces (<code>alt={&lt;2,4&gt;{green}{}}</code>). TikZ splits its options at commas before the key ever sees them. Without the braces, the parser tries to send <code>&lt;2</code> only to <code>alt</code>, and <code>4&gt;{green}{}</code> as a separate key. This</p>
<p>The original answer ended by warning that the picture would jiggle when a border got thicker, and suggested avoiding relative positioning. The real culprits are two side effects of the line width:</p>
<ul>
<li>TikZ puts a node’s anchors half a line width outside its border, so a thicker border moves the anchors, and any node positioned relative to them. Setting <code>outer sep</code> to a fixed value at least half the thickest line width (<code>ultra thick</code> is 1.6pt) stops that. Positioning with <code>on grid</code> (center to center) helps too.</li>
<li>A thicker border also makes the picture’s bounding box bigger, and beamer re-centers the bigger picture. Pinning the bounding box to the (now fixed) node anchors stops that.</li>
</ul>
<p>Relative positioning is fine after all.</p>
<p>Smaller modernizations: <code>\tikzset{highlight/.style=...}</code> replaces the deprecated <code>\tikzstyle</code>, <code>align=center</code> replaces <code>text centered</code>, and <code>\centering</code> replaces the <code>figure</code> and <code>centering</code> environments.</p>
<!-- TODO: anything else you'd do differently now? e.g. whether you still use
     beamer for teaching, or other tools you'd reach for. -->


</section>

 ]]></description>
  <category>latex</category>
  <category>beamer</category>
  <category>tikz-pgf</category>
  <guid>https://www.matthewleingang.com/blog/posts/2026-11-23-beamer-overlays-tikz-revisited/</guid>
  <pubDate>Mon, 23 Nov 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Back to writing</title>
  <link>https://www.matthewleingang.com/blog/posts/2026-11-21-a-new-chapter-again/</link>
  <description><![CDATA[ 





<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://www.matthewleingang.com/blog/posts/2026-11-21-a-new-chapter-again/typewriter.jpg" class="img-fluid figure-img" alt="A black vintage Favorit typewriter seen from above on a white background, with a blank sheet of paper loaded."></p>
<figcaption>Photo by <a href="https://commons.wikimedia.org/wiki/File:Vintage_typewriter_(Unsplash).jpg">Florian Klauer</a>, public domain (CC0).</figcaption>
</figure>
</div>
<p>A while back I spent a summer rewriting my website. I changed from a dynamic, database-backed platform to a static site generated from text files. I migrated my Drupal and WordPress sites to the new platform. I tweaked a theme until I was satisfied with its style. I learned a lot of Python and <a href="https://www.makotemplates.org/">Mako</a> along the way. It was a worthwhile summer project.</p>
<p>Once the academic year started, I lost energy, and kept my focus on my day job of teaching, training teachers, and student affairs. Not long after that the COVID-19 pandemic hit, and lots of priorities shifted.</p>
<p>I stepped down from departmental leadership in 2025. The position of Vice Chair for Undergraduate Affairs was retired in 2023 and split into two Assistant Directors for Undergraduate Studies (no wonder I was too busy to write!). The two posts are on staggered four-year terms. I took the first half-term as a transition to the new organization.</p>
<p>Now I am “only” a Clinical Professor. I teach a full load of three courses per semester, advise students, and serve on a few committees. I have been enjoying the authority without responsibility that my veteran status confers. And I also find I have more time to focus on my own students, and personal professional development. In the meantime, the nest has emptied: my youngest child has entered college, and my oldest has graduated.</p>
<p>I switched to the <a href="https://quarto.org/">Quarto</a> platform. It seems to facilitate easy publication of lots of different documents, including Jupyter notebooks. Also, I can keep everything in one GitHub repository while publishing two websites: this one along with my <a href="https://cims.nyu.edu/~leingang/">office page</a> for my current students and colleagues. Incredibly, Claude facilitated this migration in a matter of hours, instead of the months it took me to set up my Nikola site.</p>
<p>I’m looking forward to sharing more of the things I’ve been doing, now that I have the time to write about it.</p>



 ]]></description>
  <category>meta</category>
  <guid>https://www.matthewleingang.com/blog/posts/2026-11-21-a-new-chapter-again/</guid>
  <pubDate>Sat, 21 Nov 2026 00:00:00 GMT</pubDate>
  <media:content url="https://www.matthewleingang.com/blog/posts/2026-11-21-a-new-chapter-again/typewriter.jpg" medium="image" type="image/jpeg" height="108" width="144"/>
</item>
<item>
  <title>Why is the vector field \(\left&lt; y,0 \right&gt;\) not conservative?</title>
  <link>https://www.matthewleingang.com/blog/answers/2026-11-17-math-why-vector-field-fx-y-y-0-is-not-conservative/</link>
  <description><![CDATA[ 





<div class="se-question callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The question
</div>
</div>
<div class="callout-body-container callout-body">
<p>Math Stack Exchange user <a href="https://math.stackexchange.com/users/1781165/kolkatas">Kolkatas</a> <a href="https://math.stackexchange.com/questions/5154532/why-vector-field-fx-y-y-0-is-not-conservative">asks</a> (2026-11-17; <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>):</p>
<blockquote class="blockquote">
<p>I want to check if the vector field <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D(x,y)=%5Cleft%3C%20y,0%20%5Cright%3E"> is conservative.</p>
<p>On Desmos, the picture of this vector field in the upper half-plane shows horizontal arrows pointing to the right.</p>
<p>Since there is no circle, I thought that it was conservative.</p>
<p>But with <img src="https://latex.codecogs.com/png.latex?P(x,y)=y"> and <img src="https://latex.codecogs.com/png.latex?Q(x,y)=0">, we see that <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D%20%5Cneq%20%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D"> at any point in the domain.</p>
<p><strong>What is my mistake in understanding?</strong></p>
</blockquote>
</div>
</div>
<p>“There is no circle” is too reductive a restatement of the condition that there must be no <em>rotation</em> in a conservative vector field. The more precise statement comes from the curl, as you computed.</p>
<p>But you can still find the circles. Notice <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D(x,y)%0A=%20%5Cleft%3C%20%5Cfrac%7By%7D%7B2%7D,%5Cfrac%7Bx%7D%7B2%7D%5Cright%3E%20+%20%5Cleft%3C%20%5Cfrac%7By%7D%7B2%7D,-%5Cfrac%7Bx%7D%7B2%7D%5Cright%3E%0A=%20%5Cnabla%5Cleft(%5Cfrac%7Bxy%7D%7B2%7D%5Cright)+%20%5Cleft%3C%20%5Cfrac%7By%7D%7B2%7D,-%5Cfrac%7Bx%7D%7B2%7D%5Cright%3E%0A"> So <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D"> differs from a circular vector field by a conservative vector field.</p>
<p>I expanded on this answer, with an interactive demo, in <a href="../../../blog/posts/2026-11-28-visualizing-nonconservative-vector-fields/">Visualizing nonconservative vector fields</a>.</p>
<div class="se-attribution">
<p>Originally posted as <a href="https://math.stackexchange.com/questions/5154532/why-vector-field-fx-y-y-0-is-not-conservative/5154540#5154540">an answer</a> on Mathematics Stack Exchange, 2026-11-17. Licensed <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>.</p>
</div>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a></div></div></section></div> ]]></description>
  <category>math.se</category>
  <guid>https://www.matthewleingang.com/blog/answers/2026-11-17-math-why-vector-field-fx-y-y-0-is-not-conservative/</guid>
  <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Hold on to the memories</title>
  <link>https://www.matthewleingang.com/blog/posts/2026-08-07-hold-on-to-the-memories/</link>
  <description><![CDATA[ 





<p>Every summer, GSTEM brings high-school students to NYU for six weeks of research with mentors in science, technology, engineering and math. The program’s mission, in a phrase I coined a few years ago, is <em>raising representation through mentorship and community</em>. I’ve been with it since the beginning, and I give a speech at the start and the end of each summer. This is the closing speech, lightly edited for those who weren’t in the room.</p>
<section id="thirty-nine-days" class="level2">
<h2 class="anchored" data-anchor-id="thirty-nine-days">Thirty-nine days</h2>
<p>Thirty-nine days ago, on the first day of GSTEM, I made a few predictions:</p>
<ul>
<li>You will learn things here that you couldn’t learn anywhere else.</li>
<li>You will achieve things you didn’t think possible.</li>
<li>You will form close friendships here, some of which will be lifelong.</li>
</ul>
<p>I’m back again to put the other bookend on this program. I think I got all three right.</p>
</section>
<section id="gstem-by-the-year" class="level2">
<h2 class="anchored" data-anchor-id="gstem-by-the-year">GSTEM by the year</h2>
<p>Over the years I’ve come up with a few other ways to picture this program that I’ve fathered into teenagerdom.</p>
<p>In 2023, GSTEM turned 10. That summer was overwhelmed by two blockbuster movies, <em>Barbie</em> and <em>Oppenheimer</em>. <a href="https://knowyourmeme.com/memes/barbenheimer">Memes like this one</a> were everywhere, contrasting two clashing (or maybe just complementary) personalities: fun and flirty versus hard-bitten genius. I thought it described well what our students go through in the program. They can thrive and grow in every facet of their personalities.</p>
<p><img src="https://www.matthewleingang.com/blog/posts/2026-08-07-hold-on-to-the-memories/barbenheimer.jpg" class="img-fluid" alt="A two-panel meme. On the left, Barbie, smiling in a pink convertible, is labeled “GSTEM student.” On the right, a black-and-white close-up of Oppenheimer in a fedora with a cigarette is also labeled “GSTEM student.”"></p>
<p>In 2024 we were overwhelmed with fizzy pop bangers, among them Charli XCX’s album <em>Brat</em>, and it was <a href="https://knowyourmeme.com/memes/brat-summer">brat summer</a>. At the time she said “brat is a girl who is messy but also honest, sometimes has a breakdown but parties through it.” I thought that described the STEM experience well: messy, honest, unpredictable, and improved by collaboration.</p>
<p><img src="https://www.matthewleingang.com/blog/posts/2026-08-07-hold-on-to-the-memories/gstem-brat.png" class="img-fluid" alt="The word “gstem” in lowercase dark gray letters on a lime-green background, in the style of the cover of Charli XCX's album Brat."></p>
<p>Last year, well, last year was kind of bleak. The government felt emboldened to suppress what it saw as wrongthink. Some of our mentors couldn’t participate because their funding had been revoked, or because they feared taking part would cost them their funding.</p>
<p>This is why pipeline programs like GSTEM are so important: when young people turn away from STEM careers, they very rarely turn back. Every day the government antagonizes science, we lose a few more future scientists. Some of them will work in other countries, and some will just never materialize. Either way, as a society, we lose the breakthroughs and the economic power that STEM careers generate. Punishing science for ideological reasons is the epitome of cutting off your nose to spite your face.</p>
</section>
<section id="a-rebound-year" class="level2">
<h2 class="anchored" data-anchor-id="a-rebound-year">A rebound year</h2>
<p>This year feels more like a rebound. New York had an incredible summer:</p>
<ul>
<li>One of the host cities for the <a href="https://en.wikipedia.org/wiki/2026_FIFA_World_Cup">2026 World Cup</a></li>
<li><a href="https://www.fox5ny.com/news/nyc-ship-parade-sail4th-america-250-hudson-river-new-york-city">America’s 250th birthday</a></li>
<li><a href="https://en.wikipedia.org/wiki/Wedding_of_Taylor_Swift_and_Travis_Kelce">A royal wedding</a> (Taylor Swift and Travis Kelce) in the World’s Most Famous Arena</li>
<li><a href="https://www.nbcnewyork.com/weather/weather-stories/air-quality-ny-nj-today-canada-wildfire-smoke-forecast/6526034/">Smoke from Canadian wildfires</a> that turned the sky orange.</li>
<li><a href="https://www.pbs.org/newshour/health/u-s-officials-declare-an-end-to-record-setting-cyclospora-outbreak-but-its-origin-is-still-unknown">A cyclosporiasis outbreak</a> that made us all suddenly afraid to eat lettuce. (Among the more immediate consequences of an anti-science government.)</li>
</ul>
<p>And once more, an incredible GSTEM program. For the first time, one of the panelists in our panel discussion was an alum of the program. That was a full circle moment for us. We look forward to the day when a GSTEM alum is a GSTEM mentor.</p>
<p>To this year’s students: even though we predicted it, we are once again astonished by what you accomplished. And I suspect your parents are too.</p>
<p>So where do we stand, one year later from one year later? Right where we belong. I think it’s best expressed in a short rhyme, which evokes another unique New York phenomenon of the Summer of 2026:</p>
<blockquote class="blockquote">
<div class="line-block">Our students are <strong>shining</strong><br>
Our parents are <strong>beaming</strong><br>
GSTEM is alive<br>
<strong><a href="https://knowyourmeme.com/memes/my-mayor-muslim-my-bagels-jewish-my-christian-dior-knicks-in-four">Knicks in five!</a></strong></div>
</blockquote>
</section>
<section id="thanks" class="level2">
<h2 class="anchored" data-anchor-id="thanks">Thanks</h2>
<p>It takes a village to raise a child. These are some of our villagers:</p>
<ul>
<li>The Alfred P. Sloan Foundation, without whose support this program never would have gotten off the ground.</li>
<li>The Winston Foundation, whose support lets us include the ever more important field of data science.</li>
<li>SquarePoint, Kim and Shelley Goldenberg, and our anonymous donors.</li>
<li>Our mentors: thank you for paying it forward.</li>
<li>The NYU staff across the university who make the program possible, and our course assistants, who were always ready to do the needful.</li>
</ul>
<p>And Catherine Tissot. This is the part where I try to make her cry.</p>
<p>Catherine has worked tirelessly to put GSTEM on the map, to widen its reach and deepen its impact. She is truly dedicated to the GSTEM mission and to every one of its participants. I don’t think any of our students actually work around the clock, but at any hour of the day, some student is working and Catherine is supporting them. She pulled it off again. She loves her job, and we love her back.</p>
</section>
<section id="take-it-home-with-you" class="level2">
<h2 class="anchored" data-anchor-id="take-it-home-with-you">Take it home with you</h2>
<p>It’s time to say goodbye, but not farewell. You have papers to write! When you leave, take home with you:</p>
<ul>
<li><strong>Lifelong friendships.</strong> As New York’s most famous newlywed said: “Hold on to the memories, they will hold on to you.”</li>
<li><strong>A network of professional contacts</strong> for advice and connections going forward.</li>
<li><strong>Plans for the future.</strong> We would welcome your application to NYU!</li>
</ul>
<p>Tomorrow, get ready for the next step in your lives and your careers.</p>


</section>

 ]]></description>
  <category>gstem</category>
  <category>mentoring</category>
  <guid>https://www.matthewleingang.com/blog/posts/2026-08-07-hold-on-to-the-memories/</guid>
  <pubDate>Fri, 07 Aug 2026 00:00:00 GMT</pubDate>
  <media:content url="https://www.matthewleingang.com/blog/posts/2026-08-07-hold-on-to-the-memories/gstem-brat.png" medium="image" type="image/png" height="81" width="144"/>
</item>
<item>
  <title>Integration of \(3x^2ydx+x^3dy\) by two methods</title>
  <link>https://www.matthewleingang.com/blog/answers/2021-06-11-math-integration-of-3x2ydxx3dy-by-two-methods/</link>
  <description><![CDATA[ 





<div class="se-question callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The question
</div>
</div>
<div class="callout-body-container callout-body">
<p>Math Stack Exchange user <a href="https://math.stackexchange.com/users/87430/aarbee">aarbee</a> <a href="https://math.stackexchange.com/questions/4169996/integration-of-3x2ydxx3dy-by-two-methods">asks</a> (2021-06-11; <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>):</p>
<blockquote class="blockquote">
<blockquote class="blockquote">
<p>Find <img src="https://latex.codecogs.com/png.latex?%5Cint(3x%5E2ydx+x%5E3dy)"></p>
</blockquote>
<p><img src="https://latex.codecogs.com/png.latex?%5Cint(3x%5E2ydx+x%5E3dy)=%5Cint%20d(x%5E3y)=x%5E3y+c"></p>
<p>Or, <img src="https://latex.codecogs.com/png.latex?%5Cint(3x%5E2ydx+x%5E3dy)=%5Cint3x%5E2ydx+%5Cint%20x%5E3dy=x%5E3y+x%5E3y+c=2x%5E3y+c"></p>
<p>Why am I getting different answers from the two methods?</p>
<p>I am certain that the first method is correct.</p>
<p>About the second, I took one variable as constant while integrating. Is this wrong? Is this leading to the wrong answer? If yes, how to get the correct answer from this method? i.e.&nbsp;without the exact differential form, can we integrate to get the answer?</p>
<p>Thanks.</p>
<p><strong>EDIT:</strong> With the help of the comments, I am able to do this now:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cint(3x%5E2ydx+x%5E3dy)=%5Cint3x%5E2ydx+%5Cint%20x%5E3dy=x%5E3y+f(y)+x%5E3y+g(x)"></p>
<p>Can you guide how to proceed next? Thanks.</p>
</blockquote>
</div>
</div>
<p>Essentially, you’re asking what’s wrong with this (obviously wrong) “identity:” <img src="https://latex.codecogs.com/png.latex?%5Ccolor%7Bred%7D%7B%0A%20%20%20%20f%20=%20%5Cint%20df%20=%20%5Cint%20%5Cleft(%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%5C,dx%20+%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D%5C,dy%5Cright)%20=%20%5Cint%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%5C,dx%20+%20%5Cint%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D%5C,dy%20=%20f%20+%20f%20=%202f%0A%7D"></p>
<p>I think it’s in the step where you identify <img src="https://latex.codecogs.com/png.latex?%5Cint%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%5C,dx%20%20=%20f">. Consider a curve <img src="https://latex.codecogs.com/png.latex?C"> parametrized by <img src="https://latex.codecogs.com/png.latex?(x(t),y(t))"> over an interval <img src="https://latex.codecogs.com/png.latex?a%20%5Cleq%20t%20%5Cleq%20b">. Then <img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cint_C%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%5C,dx%0A%20%20%20%20&amp;=%20%5Cint_a%5Eb%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D(x(t),y(t))x'(t)%5C,dt%0A%5Cend%7Balign*%7D"> We can’t integrate this to <img src="https://latex.codecogs.com/png.latex?%5Cleft.f(x(t),y(t))%5Cright%7C%5Eb_a"> unless <img src="https://latex.codecogs.com/png.latex?y'(t)%20=%200">.</p>
<p>On the other hand, we can substitute for <img src="https://latex.codecogs.com/png.latex?C"> an <img src="https://latex.codecogs.com/png.latex?L">-shaped path <img src="https://latex.codecogs.com/png.latex?C_1+C_2">, where <img src="https://latex.codecogs.com/png.latex?C_1"> is the horizontal line from <img src="https://latex.codecogs.com/png.latex?(x(a),y(a))"> to <img src="https://latex.codecogs.com/png.latex?(x(b),y(a))">, and <img src="https://latex.codecogs.com/png.latex?C_2"> is the vertical line from <img src="https://latex.codecogs.com/png.latex?(x(b),y(a))"> to <img src="https://latex.codecogs.com/png.latex?(x(b),y(b))">.<br>
<img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Balign*%7D%0A%20%20%20%20%5Cint_%7BC_1%7D%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%5C,dx%0A%20%20%20%20&amp;=%20%5Cint_a%5Eb%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D(x(t),y(a))%5C,x'(t)%5C,dt%0A%20%20%20%20%5C%5C&amp;=%20f(x(b),y(a))%20-%20f(x(a),y(a))%0A%20%20%20%20%5C%5C%5Cint_%7BC_2%7D%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D%5C,dy%0A%20%20%20%20&amp;=%20%5Cint_a%5Eb%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D(x(b),y(t))%5C,y'(t)%5C,dt%0A%20%20%20%20%5C%5C&amp;=%20f(x(b),y(b))%20-%20f(x(b),y(a))%0A%5Cend%7Balign*%7D"> The two of these add up to <img src="https://latex.codecogs.com/png.latex?f(x(b),y(b))%20-%20f(x(a),y(a))%20=%20%5Cint_C%20df">.</p>
<p>The same split, <img src="https://latex.codecogs.com/png.latex?%5Cint%20%5Cvec%20F%5Ccdot%20d%5Cvec%20r%20=%20%5Cint%20F_x%5C,dx%20+%20%5Cint%20F_y%5C,dy">, is behind <a href="../../../blog/answers/2017-05-11-math-why-cant-all-vector-functions-not-be-gradient-of-a-scalar-fu/">another question</a>, where it seems to show that every vector field is a gradient.</p>
<div class="se-attribution">
<p>Originally posted as <a href="https://math.stackexchange.com/questions/4169996/integration-of-3x2ydxx3dy-by-two-methods/4170057#4170057">an answer</a> on Mathematics Stack Exchange, 2021-06-11, with <a href="https://math.stackexchange.com/posts/4170057/revisions">edits</a> by <a href="https://math.stackexchange.com/users/1361661/integreek">Integreek</a>. Licensed <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>.</p>
</div>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a></div></div></section></div> ]]></description>
  <category>math.se</category>
  <guid>https://www.matthewleingang.com/blog/answers/2021-06-11-math-integration-of-3x2ydxx3dy-by-two-methods/</guid>
  <pubDate>Fri, 11 Jun 2021 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Does zero curl imply a conservative field?</title>
  <link>https://www.matthewleingang.com/blog/answers/2018-02-05-math-does-zero-curl-imply-a-conservative-field/</link>
  <description><![CDATA[ 





<div class="se-question callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The question
</div>
</div>
<div class="callout-body-container callout-body">
<p>Math Stack Exchange user <a href="https://math.stackexchange.com/users/426411/john-a">John A.</a> <a href="https://math.stackexchange.com/questions/2635850/does-zero-curl-imply-a-conservative-field">asks</a> (2018-02-04; <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>):</p>
<blockquote class="blockquote">
<p>A field that is conservative must have a curl of zero everywhere. However, I was wondering whether the opposite holds for functions continuous everywhere: if the curl is zero, is the field conservative? Can someone please give me an intuitive explanation and insight into this, and if it is true, why? Also, please try to not be too rigorous (only in grade 9).</p>
</blockquote>
</div>
</div>
<p>You have to keep in mind that a vector field is not just a set of functions, but also a domain. For instance, the vector field <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BF%7D%20=%20%5Cleft%3C-%5Cfrac%7By%7D%7Bx%5E2+y%5E2%7D,%5Cfrac%7Bx%7D%7Bx%5E2+y%5E2%7D%5Cright%3E"> on the set <img src="https://latex.codecogs.com/png.latex?U%20=%20%5Cleft%5C%7B(x,y)%20%5Cneq%20(0,0)%5Cright%5C%7D"> has a curl of zero. But it’s not conservative, because integrating it around the unit circle results in <img src="https://latex.codecogs.com/png.latex?2%5Cpi">, not zero as predicted by path-independence.</p>
<p>On the other hand, the same vector field restricted to <img src="https://latex.codecogs.com/png.latex?U'%20=%20%5Cleft%5C%7Bx%3E0%5Cright%5C%7D"> is conservative. A potential function is <img src="https://latex.codecogs.com/png.latex?f(x,y)%20=%20%5Carctan%5Cleft(%5Cfrac%7By%7D%7Bx%7D%5Cright)">.</p>
<p>The difference is that <img src="https://latex.codecogs.com/png.latex?U'"> is simply connected, while <img src="https://latex.codecogs.com/png.latex?U"> is not. In fact, this is a symbolic version of <a href="https://math.stackexchange.com/questions/2635850/does-zero-curl-imply-a-conservative-field/2636812#2636812">M. Winter’s graphical example</a>.</p>
<p>I expanded on this example, with an interactive demo, in <a href="../../../blog/posts/2026-11-30-a-vortex-that-doesnt-rotate/">A vortex that doesn’t rotate</a>.</p>
<div class="se-attribution">
<p>Originally posted as <a href="https://math.stackexchange.com/questions/2635850/does-zero-curl-imply-a-conservative-field/2637176#2637176">an answer</a> on Mathematics Stack Exchange, 2018-02-05. Licensed <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>.</p>
</div>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a></div></div></section></div> ]]></description>
  <category>math.se</category>
  <guid>https://www.matthewleingang.com/blog/answers/2018-02-05-math-does-zero-curl-imply-a-conservative-field/</guid>
  <pubDate>Mon, 05 Feb 2018 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Why is this vector field not conservative, even though it has a potential?</title>
  <link>https://www.matthewleingang.com/blog/answers/2017-10-20-math-why-is-this-vector-field-not-conservative-even-though-it-has/</link>
  <description><![CDATA[ 





<div class="se-question callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The question
</div>
</div>
<div class="callout-body-container callout-body">
<p>Math Stack Exchange user <a href="https://math.stackexchange.com/users/179404/rax-adaam">Rax Adaam</a> <a href="https://math.stackexchange.com/questions/2481593/why-is-this-vector-field-not-conservative-even-though-it-has-a-potential-what">asks</a> (2017-10-20; <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>):</p>
<blockquote class="blockquote">
<p>My question is really ‘’what is <em>the</em> definition of a conservative vector field’’?</p>
<p>I’ve consulted three textbooks that all say a vector field <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D"> is conservative by definition if there exists a scalar potential <img src="https://latex.codecogs.com/png.latex?%5Cphi"> such that <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20%5Cphi%20=%20%5Cvec%7BF%7D">. Then, they go on to talk about connected domains, path independence and the equality of mixed partials and how they are all related.</p>
<p>In particular, they emphasize that e.g.&nbsp;in <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BR%7D%5E2"> given <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D%20=%20%5Cbigl%3CF_1,%5C,F_2%5Cbigr%3E">, if <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20F_1%7D%7B%5Cpartial%20y%7D%20=%20%5Cfrac%7B%5Cpartial%20F_2%7D%7B%5Cpartial%20x%7D"> on a simply-connected domain, then <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D"> is conservative on that domain.</p>
<p>However, without fail, all of them then offer the example of <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D%20=%20%5Cbigl%3C%20%5Cfrac%7B-y%7D%7Bx%5E2+y%5E2%7D,%5C,%20%5Cfrac%7Bx%7D%7Bx%5E2+y%5E2%7D%20%5Cbigr%3E">, pointing out:</p>
<ol type="1">
<li>it’s line integral is <em>not</em> path independent, even though</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20F_1%7D%7B%5Cpartial%20y%7D%20=%20%5Cfrac%7B%5Cpartial%20F_2%7D%7B%5Cpartial%20x%7D"></li>
</ol>
<p>and this is explained by pointing out that the domain is not simply connected (if the path contains the origin).</p>
<p>That much makes sense to me: we cannot conclude <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D"> is conservative based on the partial derivatives, because the domain is not simply connected - totally consistent with what has been presented.</p>
<p><strong>What none of them address is why <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D%20=%20%5Cbigl%3C%20%5Cfrac%7B-y%7D%7Bx%5E2+y%5E2%7D,%5C,%20%5Cfrac%7Bx%7D%7Bx%5E2+y%5E2%7D%20%5Cbigr%3E"> is not conservative when there exists a potential <img src="https://latex.codecogs.com/png.latex?%5Cphi%20=%20%5Carctan(y/x)"> such that <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20%5Cphi%20=%20%5Cvec%7BF%7D"></strong>. None of the texts mention any necessary conditions on the scalar potential. So is the existence of a scalar potential the definition of a vector field being conservative or not?</p>
</blockquote>
</div>
</div>
<p>Any mapping, be it a vector field or a scalar function or something else, requires a domain.</p>
<p>It is true that where <img src="https://latex.codecogs.com/png.latex?%5Cphi(x,y)"> is defined, <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20%5Cphi%20=%20%5Cvec%20F">. But <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F">’s domain is the plane minus the origin, while <img src="https://latex.codecogs.com/png.latex?%5Cphi">’s domain is the plane minus a line (the <img src="https://latex.codecogs.com/png.latex?y">-axis).</p>
<p>Since there’s no function <em>with the same domain as <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"></em> whose gradient is <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F">, <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> is not conservative.</p>
<p>Notice that the right half of the plane is simply connected. The vector field <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> restricted to that domain is conservative. The function <img src="https://latex.codecogs.com/png.latex?%5Cphi"> works as a potential on that domain.</p>
<p>The upshot is that the question of whether <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> is conservative on <img src="https://latex.codecogs.com/png.latex?U"> is a question not just about the component functions of <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> but the “shape” (we say <em>topology</em>) of <img src="https://latex.codecogs.com/png.latex?U">.</p>
<p>I expanded on this answer, with an interactive demo, in <a href="../../../blog/posts/2026-11-30-a-vortex-that-doesnt-rotate/">A vortex that doesn’t rotate</a>.</p>
<div class="se-attribution">
<p>Originally posted as <a href="https://math.stackexchange.com/questions/2481593/why-is-this-vector-field-not-conservative-even-though-it-has-a-potential-what/2481600#2481600">an answer</a> on Mathematics Stack Exchange, 2017-10-20. Licensed <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>.</p>
</div>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a></div></div></section></div> ]]></description>
  <category>math.se</category>
  <guid>https://www.matthewleingang.com/blog/answers/2017-10-20-math-why-is-this-vector-field-not-conservative-even-though-it-has/</guid>
  <pubDate>Fri, 20 Oct 2017 00:00:00 GMT</pubDate>
</item>
<item>
  <title>First Day 2017</title>
  <link>https://www.matthewleingang.com/blog/archive/2017-09-05-first-day-2017/</link>
  <description><![CDATA[ 





<p><a href="https://instagram.com/p/BYqSv82jy_f">View this photo on Instagram</a></p>
<p>Once again, the summer has vanished. Fall classes begin today. Like the students, I begin the year with excitement, anxiety, and hope.</p>
<p>It’s the beginning of my 10th year at NYU. That means in a year I’ll be invited to a “longer service recognition” reception.</p>
<p>The sidewalks are bustling with eager students, gnawing bagels and walking fast. I heard some of them helping others out with directions. And this is only at 9:15. By the middle of the day the crowds will be even bigger.</p>
<p>I’m teaching an honors section of Calculus III and a section of Discrete Mathematics. I haven’t taught discrete in a long time, and I’ve never taught Calculus III out of the honors textbook (Marsden &amp; Tromba). I’m hoping my students will be stimulated, challenged, and engaged.</p>
<p>I’ve got a fresh set of <a href="http://www.wikihow.com/Play-Human-Bingo">Human Bingo</a> cards created. One of my summer projects was beefing up an old python script to create them (with custom fields from a data file) into a bona fide <a href="https://pypi.python.org/pypi/humanbingo">PyPI project</a>.</p>
<p>And, once again, I have to download rosters from various websites (our SIS and LMS sites) and upload them to other sites. Having polished command-line tools makes this job so much easier. Especially since I included documentation or at least <code>--help</code>.</p>



 ]]></description>
  <category>NYU</category>
  <category>instagram</category>
  <guid>https://www.matthewleingang.com/blog/archive/2017-09-05-first-day-2017/</guid>
  <pubDate>Tue, 05 Sep 2017 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Why can’t all vector functions not be gradient of a scalar function?</title>
  <link>https://www.matthewleingang.com/blog/answers/2017-05-11-math-why-cant-all-vector-functions-not-be-gradient-of-a-scalar-fu/</link>
  <description><![CDATA[ 





<div class="se-question callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The question
</div>
</div>
<div class="callout-body-container callout-body">
<p>Math Stack Exchange user <a href="https://math.stackexchange.com/users/419536/joe">Joe</a> <a href="https://math.stackexchange.com/questions/2276588/why-cant-all-vector-functions-not-be-gradient-of-a-scalar-function">asks</a> (2017-05-11; <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>):</p>
<blockquote class="blockquote">
<p>If we define <img src="https://latex.codecogs.com/png.latex?W=%5Cint%20%5Cvec%7BF%7D.%5Cvec%7Bdr%7D">, we obtain <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D=%5Cvec%7B%5Ctriangledown%7DW">.</p>
<p>Now for any <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D"> we can define such an <img src="https://latex.codecogs.com/png.latex?W">; and therefore any <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D"> can be written as the gradient of a scalar function (W).</p>
<p>This is obviously not the case as there are indeed many vector functions which can’t be written as the gradient of a scalar function. Therefore I am wrong somewhere. Can anybody point out where?</p>
<blockquote class="blockquote">
<p>Edit: I understood the point. However my following calculation has something wrong. Please point it out.</p>
</blockquote>
<blockquote class="blockquote">
<p>By definition of work:</p>
</blockquote>
<blockquote class="blockquote">
<p><img src="https://latex.codecogs.com/png.latex?W=%5Cint%20%5Cvec%7BF%7D.%5Cvec%7Bdr%7D"> for any <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D"> <img src="https://latex.codecogs.com/png.latex?=%5Cint%20%20F_x%20dx+%5Cint%20F_y%20dy"> (for any path C, the dot product can be splitted into its components)</p>
</blockquote>
<blockquote class="blockquote">
<p>Differentiating both sides wrt x: <img src="https://latex.codecogs.com/png.latex?F_x=%5Cdfrac%7BdW%7D%7Bdx%7D"> and differentiating both sides wrt y: <img src="https://latex.codecogs.com/png.latex?F_y=%5Cdfrac%7BdW%7D%7Bdy%7D"> and therefore for any <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D"> <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D=%5Cvec%7B%5Ctriangledown%7DW"></p>
</blockquote>
</blockquote>
</div>
</div>
<p>The notation <img src="https://latex.codecogs.com/png.latex?W%20=%20%5Cint%20%5Cvec%20F%5Ccdot%20d%5Cvec%20r"> elides an important detail: the path along which <img src="https://latex.codecogs.com/png.latex?F"> is to be integrated. The usual construction is to integrate along a path that starts at a fixed point <img src="https://latex.codecogs.com/png.latex?p"> and ends at a variable point <img src="https://latex.codecogs.com/png.latex?x">. But there are two trouble spots with this construction.</p>
<p>The first is not so bad. How do we know that there <em>is</em> a path from <img src="https://latex.codecogs.com/png.latex?p"> to each point <img src="https://latex.codecogs.com/png.latex?x">? So we have to add the assumption that the domain of <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> is <em>connected</em>, or technically <em>path-connected</em>. If the domain is connected, we at least have a <img src="https://latex.codecogs.com/png.latex?W(x)"> for each <img src="https://latex.codecogs.com/png.latex?x">.</p>
<p>The second is trickier. <img src="https://latex.codecogs.com/png.latex?W"> needs to be a function, and it should depend only on <img src="https://latex.codecogs.com/png.latex?x">, not on the specific path one takes from <img src="https://latex.codecogs.com/png.latex?p"> to <img src="https://latex.codecogs.com/png.latex?x">. Otherwise you and I could accidentally pick different paths and get different results, and we wouldn’t know which one to call <img src="https://latex.codecogs.com/png.latex?W(x)">. So <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> needs the property that line integrals are independent of path. This is equivalent to the property that line integrals around closed loops are zero.</p>
<p>If line integrals around closed loops are zero, it follows from Stokes’s theorem that <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20%5Ctimes%20%5Cvec%20F%20=%20%5Cvec%200">. And the implication <em>almost</em> goes in the other way, too, except for the possibility that the path wraps around a “hole” in the domain. Try <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F(x,y,z)%20=%20%5Cleft%3C-%20%5Cfrac%7By%7D%7Bx%5E2+y%5E2%7D,%20%5Cfrac%7Bx%7D%7Bx%5E2+y%5E2%7D,0%5Cright%3E"> Then <img src="https://latex.codecogs.com/png.latex?%5Cnabla%20%5Ctimes%20%5Cvec%20F%20=%20%5Cvec%200">. However, the domain of <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> excludes the <img src="https://latex.codecogs.com/png.latex?z">-axis, where <img src="https://latex.codecogs.com/png.latex?x=y=0">. And in fact, if we integrate <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> around the unit circle in the <img src="https://latex.codecogs.com/png.latex?xy">-plane, we get <img src="https://latex.codecogs.com/png.latex?2%5Cpi">, not <img src="https://latex.codecogs.com/png.latex?0">. So this <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> is not conservative, despite it having a curl of zero.</p>
<p>So we rule out that possibility and require that the domain of <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> be not just connected but <em>simply connected</em>: that any closed loop in the domain is contractible to a point. Picture a slipknot closing up. If the domain has no holes, a loop in the domain can contract to a point, but if there is a hole, a loop around that hole can’t move “past” it.</p>
<p>So if <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> has a curl of zero, and the domain of <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> is connected and simply connected, your construction does result in a potential function and proves that <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> is conservative.</p>
<p>It’s worth noting that the sufficient conditions are not just differential (<img src="https://latex.codecogs.com/png.latex?%5Cnabla%20%5Ctimes%20%5Cvec%20F%20=%20%5Cvec%200">), but topological (domain is connected and simply connected). To follow this point, if we have a domain and we want to know more about its shape, we might try to construct vector fields with zero curl but which aren’t conservative. If we could find one, we would know the domain is not simply connected. This kind of study is called <em>algebraic topology</em>.</p>
<p>I expanded on the example <img src="https://latex.codecogs.com/png.latex?%5Cleft%3C%20-y/(x%5E2+y%5E2),%20x/(x%5E2+y%5E2)%20%5Cright%3E">, with an interactive demo, in <a href="../../../blog/posts/2026-11-30-a-vortex-that-doesnt-rotate/">A vortex that doesn’t rotate</a>. And the splitting step in your edit, <img src="https://latex.codecogs.com/png.latex?%5Cint%20%5Cvec%20F%5Ccdot%20d%5Cvec%20r%20=%20%5Cint%20F_x%5C,dx%20+%20%5Cint%20F_y%5C,dy">, goes wrong the same way as in <a href="../../../blog/answers/2021-06-11-math-integration-of-3x2ydxx3dy-by-two-methods/">this later question</a>.</p>
<div class="se-attribution">
<p>Originally posted as <a href="https://math.stackexchange.com/questions/2276588/why-cant-all-vector-functions-not-be-gradient-of-a-scalar-function/2276652#2276652">an answer</a> on Mathematics Stack Exchange, 2017-05-11. Licensed <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>.</p>
</div>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a></div></div></section></div> ]]></description>
  <category>math.se</category>
  <guid>https://www.matthewleingang.com/blog/answers/2017-05-11-math-why-cant-all-vector-functions-not-be-gradient-of-a-scalar-fu/</guid>
  <pubDate>Thu, 11 May 2017 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Determining whether a vector field is conservative</title>
  <link>https://www.matthewleingang.com/blog/answers/2017-04-25-math-determining-whether-a-vector-field-is-conservative/</link>
  <description><![CDATA[ 





<div class="se-question callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The question
</div>
</div>
<div class="callout-body-container callout-body">
<p>Math Stack Exchange user <a href="https://math.stackexchange.com/users/369262/user369262">user369262</a> <a href="https://math.stackexchange.com/questions/2251798/determining-whether-a-vector-field-is-conservative">asks</a> (2017-04-25; <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>):</p>
<blockquote class="blockquote">
<p>For a vector field <img src="https://latex.codecogs.com/png.latex?%5Cvec%7BF%7D(x,y,z)%20=%20%5Clangle%20F_1(x,y,z),%20F_2(x,y,z),%20F_3(x,y,z)%20%5Crangle"> in <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BR%7D%5E3">, how can I use mixed second-order partial derivatives of each of the components to determine whether it is conservative? Which partial derivatives should I compare?</p>
</blockquote>
</div>
</div>
<p>Assume the derivatives of the components of <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> are continuous functions. If <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F%20=%20%5Cleft%3CP(x,y,z),Q(x,y,z),R(x,y,z)%5Cright%3E"> were the gradient of a function <img src="https://latex.codecogs.com/png.latex?f(x,y,z)">, then <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%20=%20P%20%5Ctext%7B,%7D%5Cqquad%0A%20%20%20%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D%20=%20Q%20%5Ctext%7B,%7D%5Cqquad%5Ctext%7Band%7D%5Cqquad%0A%20%20%20%20%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20z%7D%20=%20R"> Taking the derivative of both sides of the first equation with respect to <img src="https://latex.codecogs.com/png.latex?y">, and the second equation with respect to <img src="https://latex.codecogs.com/png.latex?x">, we get <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%5E2%20f%7D%7B%5Cpartial%20y%5C,%5Cpartial%20x%7D%20=%20%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D%0A%5Cqquad%5Ctext%7Band%7D%5Cqquad%0A%20%20%20%20%5Cfrac%7B%5Cpartial%5E2%20f%7D%7B%5Cpartial%20x%5C,%5Cpartial%20y%7D%20=%20%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D"> By Clairaut’s theorem the left-hand sides of the two equations are equal. Therefore <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20y%7D%20=%20%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20x%7D"> Similarly, it can be shown that <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cpartial%20P%7D%7B%5Cpartial%20z%7D%20=%20%5Cfrac%7B%5Cpartial%20R%7D%7B%5Cpartial%20x%7D%0A%5Cqquad%5Ctext%7Band%7D%5Cqquad%0A%20%20%20%20%5Cfrac%7B%5Cpartial%20Q%7D%7B%5Cpartial%20z%7D%20=%20%5Cfrac%7B%5Cpartial%20R%7D%7B%5Cpartial%20y%7D"> These are all <strong>necessary</strong> conditions for <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> to be conservative. They can be written in a form that doesn’t assume only three variables, or, in the case of three variables, in a vector form. If these equations do not hold, <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> cannot be conservative.</p>
<p>The big question is when these conditions are <strong>sufficient</strong> as well. The answer is that as long as the domain of <img src="https://latex.codecogs.com/png.latex?%5Cvec%20F"> is connected and simply connected, they are sufficient. This follows from Stokes’s Theorem.</p>
<p>For what goes wrong when the domain is <em>not</em> simply connected, see <a href="../../../blog/answers/2018-02-05-math-does-zero-curl-imply-a-conservative-field/">Does zero curl imply a conservative field?</a> and <a href="../../../blog/posts/2026-11-30-a-vortex-that-doesnt-rotate/">A vortex that doesn’t rotate</a>.</p>
<div class="se-attribution">
<p>Originally posted as <a href="https://math.stackexchange.com/questions/2251798/determining-whether-a-vector-field-is-conservative/2251818#2251818">an answer</a> on Mathematics Stack Exchange, 2017-04-25. Licensed <a href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>.</p>
</div>



<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-reuse"><h2 class="anchored quarto-appendix-heading">Reuse</h2><div class="quarto-appendix-contents"><div><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a></div></div></section></div> ]]></description>
  <category>math.se</category>
  <guid>https://www.matthewleingang.com/blog/answers/2017-04-25-math-determining-whether-a-vector-field-is-conservative/</guid>
  <pubDate>Tue, 25 Apr 2017 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Document correlation with Nikola, NLTK, and NumPy</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-07-11-document-correlation-with-nikola-nltk-and-numpy/</link>
  <description><![CDATA[ 





<p>One nice website feature is having a set of related posts to a given post. That way a reader can quickly browse from one article to something similar. I wanted to implement this feature on my Nikola blog in a smart way, but first I had to learn something about the underlying math.</p>
<p>One way to decide if two posts are related is to check their metadata. If they are in the same category, or share one or more tags, they are probably related in some obvious sense. But humans (or at least this human) are pretty lazy with tagging and categorizing. And within the same category or shared tags, some posts will be “more” related than others. So I wanted a fulltext match instead of a metadata match.</p>
<p>In a blog with a relational database on the backend, finding posts related to a given post by fulltext matching is a relatively straightforward process. By diving into a WordPress plugin called <a href="https://wordpress.org/plugins/yet-another-related-posts-plugin/">YARPP</a>, I discovered that the whole process is window dressing for an SQL query using a <a href="https://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html">MATCH</a> keyword. The indices and query can be tweaked, but the function is already there for the using.</p>
<p>But Nikola’s “database” is posts in flat files, so the matching needs to be done by hand. Luckily, this is a math problem. A high-dimensional, linear algebra problem, which makes it a good application for numerical computing.</p>
<p>Eventually I found a <a href="https://github.com/alfanick/jekyll-related-posts">related posts</a> plugin for <a href="https://jekyllrb.com">jekyll</a>. Jekyll is a static site generator much like Nikola, but written in ruby. In studying the code for the jekyll plugin, I figured out the process.</p>
<section id="document-correlation" class="level1">
<h1>Document correlation</h1>
<p>Consider a corpus of documents (or posts) <img src="https://latex.codecogs.com/png.latex?p_1,%20p_2,%20%5Cdots,%20p_m">, written using words <img src="https://latex.codecogs.com/png.latex?w_1,%20w_2,%20%5Cdots,%20w_n">. Then each post can be represented as a vector in an an <img src="https://latex.codecogs.com/png.latex?n">-dimensional vector space, whose <img src="https://latex.codecogs.com/png.latex?j">-th component is the number of times word <img src="https://latex.codecogs.com/png.latex?j"> appears in the post. Two posts would be represented by the same vector if one were a word-by-word rearrangement of the other, which seems unlikely on a practical basis. Posts that share a lot of words should probably be considered related to each other.</p>
<p>Let <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Btc%7D"> be the <img src="https://latex.codecogs.com/png.latex?m%5Ctimes%20n"> matrix whose <img src="https://latex.codecogs.com/png.latex?(i,j)">-th entry is the number of times word <img src="https://latex.codecogs.com/png.latex?j"> appears in post <img src="https://latex.codecogs.com/png.latex?i">. The matrix <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Btc%7D"> is called the <strong>term count</strong> matrix. To normalize slightly, let <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Btf%7D"> be the matrix whose <img src="https://latex.codecogs.com/png.latex?i">-th row is the <img src="https://latex.codecogs.com/png.latex?i">-th row of <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Btc%7D"> divided by the maximum entry in the row. This is called the <strong>term frequency</strong> matrix. Each row has entries between zero and one, and the closer the entry is to one, the closer it is to being the most frequent word in the post.</p>
<p>Of course, some words are going to appear frequently no matter what the post is truly about. Words like <em>the</em>, <em>a</em>, <em>of</em>, and so on. More specifically, if your blog is all about cars, it’s not so significant if every document contains the word <em>car.</em> So term frequency needs to be controlled by how often the words appear in the corpus in general. This is where the notion of <em>inverse document frequency</em> comes in. We create a row vector <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Bidf%7D">, whose <img src="https://latex.codecogs.com/png.latex?j">-th component measures how many documents word <img src="https://latex.codecogs.com/png.latex?j"> appears in, but inverted so that the more often it appears, the smaller the component is. There are several ways to construct this measure. One popular formula is:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Bidf%7D_j%20=%20%5Cfrac%7B%5C#%5Cleft%5C%7B%5Ctext%7Bposts%7D%5Cright%5C%7D%7D%7B%5Clog(1+%5C#%5Cleft%5C%7B%5Ctext%7Bposts%20which%20contain%20word%20$j$%7D%5Cright%5C%7D)%7D"></p>
<p>The <strong>term frequency-inverse document frequency</strong> matrix is the <img src="https://latex.codecogs.com/png.latex?m%20%5Ctimes%0An"> matrix whose <img src="https://latex.codecogs.com/png.latex?(i,j)">-th entry is <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Btf%7D_%7Bij%7D%5Cmathrm%7Bidf%7D_j">. In matrix terms, the <img src="https://latex.codecogs.com/png.latex?i">-th row of <img src="https://latex.codecogs.com/png.latex?A"> is the <img src="https://latex.codecogs.com/png.latex?i">-th row of <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Btf%7D"> multiplied componentwise by <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7Bidf%7D">. Tf-idf ranks words highly if they appear relatively frequently in a post and not so frequently in the set of all posts.</p>
<p>We’ll declare two posts to be related if their rows in the tf-idf matrix are close together in <img src="https://latex.codecogs.com/png.latex?n">-dimensional space. A good measure of closeness for this discussion is the angle between the vectors. The smaller the angle, the closer the vectors. The cosine of the angle between two vectors can be computed with the dot product:</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bv%7D%5Ccdot%5Cmathbf%7Bw%7D%20=%20%5Csum_%7Bi=1%7D%5En%20v_i%20w_i"></p>
<p>The law of cosines states that</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bv%7D%5Ccdot%5Cmathbf%7Bw%7D%20=%20%7C%7C%5Cmathbf%7Bv%7D%7C%7C%20%7C%7C%20%5Cmathbf%7Bw%7D%20%7C%7C%20%5Ccos(%5Ctheta)"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> is the angle between the vectors. Therefore</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Ccos(%5Ctheta)%20=%20%5Cfrac%7B%5Cmathbf%7Bv%7D%5Ccdot%5Cmathbf%7Bw%7D%7D%7B%7C%7C%5Cmathbf%7Bv%7D%7C%7C%20%7C%7C%20%5Cmathbf%7Bw%7D%20%7C%7C%7D"></p>
<p>The rows of the tf-idf matrix (which I’m going to call <img src="https://latex.codecogs.com/png.latex?A">) are the vectors we want to measure the angles between. This can be done in one fell swoop with matrix operations. Let the rows of <img src="https://latex.codecogs.com/png.latex?A"> be called <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Ba%7D_1,%5Cdots,%5Cmathbf%7Ba%7D_n">. Let <img src="https://latex.codecogs.com/png.latex?B"> be the the matrix whose <img src="https://latex.codecogs.com/png.latex?(i,j)">-th entry is the cosine of the angle between <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Ba%7D_i"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Ba%7D_j">. We know</p>
<p><img src="https://latex.codecogs.com/png.latex?b_%7Bij%7D%20=%20%5Cfrac%7B%5Cmathbf%7Ba%7D_i%20%5Ccdot%20%5Cmathbf%7Ba%7D_j%7D%7B%7C%7C%5Cmathbf%7Ba%7D_i%7C%7C%20%7C%7C%5Cmathbf%7Ba%7D_j%7C%7C%7D"></p>
<p>Let <img src="https://latex.codecogs.com/png.latex?A%5ET"> be the transpose of <img src="https://latex.codecogs.com/png.latex?A">. Then <img src="https://latex.codecogs.com/png.latex?AA%5ET"> is the <img src="https://latex.codecogs.com/png.latex?m%0A%5Ctimes%20m"> matrix whose <img src="https://latex.codecogs.com/png.latex?(i,j)">-th entry is the dot product of <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Ba%7D_i"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Ba%7D_j">. This is because</p>
<p><img src="https://latex.codecogs.com/png.latex?(AA%5ET)_%7Bij%7D%20=%20%5Csum_%7Bk=1%7D%5En%20(A)_%7Bik%7D(A%5ET)_%7Bkj%7D%20=%20%5Csum_%7Bk=1%7D%5En%20a_%7Bik%7Da_%7Bjk%7D"></p>
<p>This matrix is symmetric, and its diagonal entries are the dot products of each row with itself. That is, <img src="https://latex.codecogs.com/png.latex?(AA%5ET)_%7Bii%7D%20=%20%5Cmathbf%7Ba%7D_i%20%5Ccdot%20%5Cmathbf%7Ba%7D_i%20=%20%7C%7C%5Cmathbf%7Ba%7D_i%7C%7C%5E2">.</p>
<p>If <img src="https://latex.codecogs.com/png.latex?B"> is the matrix whose <img src="https://latex.codecogs.com/png.latex?(i,j)">-th entry is the cosine of the angle between <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Ba%7D_i"> and <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Ba%7D_j">, we are halfway there (the numerator half) with <img src="https://latex.codecogs.com/png.latex?AA%5ET">. The denominator of <img src="https://latex.codecogs.com/png.latex?b_%7Bij%7D"> is the product <img src="https://latex.codecogs.com/png.latex?%7C%7C%5Cmathbf%7Ba%7D_i%7C%7C%20%7C%7C%5Cmathbf%7Ba%7D_j%7C%7C">. This can be constructed by letting <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bd%7D"> be the vector of the diagonal entries of <img src="https://latex.codecogs.com/png.latex?AA%5ET">, and taking the <em>outer product</em> of that vector with itself:</p>
<p><img src="https://latex.codecogs.com/png.latex?(%5Cmathbf%7Bd%7D%5ET%20%5Cmathbf%7Bd%7D)_%7Bij%7D%20=%20d_i%20d_j%20=%20%7C%7C%5Cmathbf%7Ba%7D_i%7C%7C%5E2%20%7C%7C%5Cmathbf%7Ba%7D_j%7C%7C%5E2"></p>
<p>Putting this together, we see that</p>
<p><img src="https://latex.codecogs.com/png.latex?B%20=%20%5Cfrac%7BAA%5ET%7D%7B%5Csqrt%7B%5Cmathbf%7Bd%7D%5ET%20%5Cmathbf%7Bd%7D%7D%7D"></p>
<p>where the fraction bar stands for component-by-component division of the matrices.</p>
<p>For more on the math behind this, see:</p>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Tf%E2%80%93idf">tf–idf</a> from Wikipedia</li>
<li><a href="http://nlp.stanford.edu/IR-book/html/htmledition/irbook.html">Introduction to Information Retrieval</a> by Manning, Raghavan, and Schütze</li>
<li><a href="http://www.tfidf.com/">Tf-idf :: A Single-Page Tutorial - Information Retrieval and Text Mining</a></li>
<li><a href="https://en.wikipedia.org/wiki/Cosine_similarity">Cosine similarity</a> from Wikipedia</li>
</ul>
</section>
<section id="numpy-implementation" class="level1">
<h1>Numpy implementation</h1>
<p>Nikola is written in python, and <a href="https://www.numpy.org/">Numpy</a> is a powerful library for doing calculations on large matrices. It provides lots of methods for doing matrix/vector operations quickly.</p>
<p>Here is the code that creates the term count matrix:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource python numberLines code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">class</span> RelatedPosts(ConfigPlugin):</span>
<span id="cb1-2"></span>
<span id="cb1-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ...</span></span>
<span id="cb1-4"></span>
<span id="cb1-5"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> set_term_count(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>,site):</span>
<span id="cb1-6">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""set the post-word count matrix</span></span>
<span id="cb1-7"></span>
<span id="cb1-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    set self.tc to be a matrix where</span></span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        self.tc[i,j] = # of times word j appears in post i</span></span>
<span id="cb1-11"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    """</span></span>
<span id="cb1-12">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">not</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.allwords:</span>
<span id="cb1-13">        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.set_words(site)</span>
<span id="cb1-14">    result <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> numpy.zeros((<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(site.posts),<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.allwords)))</span>
<span id="cb1-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i,post <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">enumerate</span>(site.posts):</span>
<span id="cb1-16">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># wordcount[word] is the number of times 'word' appears in the post</span></span>
<span id="cb1-17">        wordcount<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> defaultdict(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>,<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">zip</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>numpy.unique(numpy.array(post.meta(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'words'</span>)), return_counts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)))</span>
<span id="cb1-18">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> j,word <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">enumerate</span>(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.allwords):</span>
<span id="cb1-19">            result[i,j] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> wordcount[word]</span>
<span id="cb1-20">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># logger.debug("set_term_count: %s" % result)</span></span>
<span id="cb1-21">    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.tc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> result</span>
<span id="cb1-22">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> result</span></code></pre></div></div>
<p>I don’t want to go into what a <code>ConfigPlugin</code> is; read the <a href="https://getnikola.com/handbook.html">Nikola manual</a> if you want to know. The important thing to know for context is that <code>site</code> is a reference to the whole Nikola site object, and <code>site.posts</code> refers to the list of all posts. The list <code>self.allwords</code> is a list of all the words used in the site. For each post, <code>post.meta('words')</code> is a list of all the words used in the post, with multiplicity.</p>
<p>Originally I had something like <code>result[i,j] = post.meta('words').count(word)</code>, but I realized after watching the site build many times that I had introduced a lot of slowdown. I was essentially checking each word of each post against each word of the whole site. This is terribly redundant since once it matches a word, we can stop checking it! In fact, we can just make a tally of all the words in the post as a dictionary, and look up each word of the site in that dictionary. That is what <code>wordcount= defaultdict(int,zip(*numpy.unique(numpy.array(post.meta('words')), return_counts=True)))</code> does. The <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html">unique</a> function returns a tuple of unique items in the array, and their multiplicities or “counts.” This is converted into python dictionary with the <code>zip</code> function, and then into a <code>defaultdict</code> that returns zero (the <code>int</code> version of <code>None</code>) if the looked-up term is not in the post. This optimization cut the time to build by about 75%.</p>
<p>The next matrix to compute is the term frequency matrix:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource python numberLines code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">@property</span></span>
<span id="cb2-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> tf(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>):</span>
<span id="cb2-3">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""term frequency matrix</span></span>
<span id="cb2-4"></span>
<span id="cb2-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    return a matrix TF, where</span></span>
<span id="cb2-6"></span>
<span id="cb2-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        TF[i,j] = frequency of word j in post i</span></span>
<span id="cb2-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">        (relative to the most frequent word in post i)</span></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    """</span></span>
<span id="cb2-10">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._tf <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">is</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>:</span>
<span id="cb2-11">        term_count <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.tc</span>
<span id="cb2-12">        wordmax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>numpy.amax(term_count,axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-13">        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._tf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> term_count <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> wordmax[:,<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>]</span>
<span id="cb2-14">        logger.debug(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tf: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%s</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._tf)</span>
<span id="cb2-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._tf</span></code></pre></div></div>
<p>The <code>@property</code> line is an example of a python function decorator. In general, function decorators are amazing and complicated. This one is not, though: it allows us to treat the output of a function as if it were a regular property. That is, <code>self.tc</code> will return the output of <span class="title-ref">self.tc()</span>. This is just some syntactic sugar, but like sugar, it’s pretty sweet.</p>
<p>We use <em>lazy evaluation</em> to compute the tf matrix once, stash it in a “private” property <code>self._tc</code>, and after subsequent calls just return that private property. Remember no properties are <em>really</em> private in Python, but the leading underscore is customary for properties you don’t want people to mess with.</p>
<p>Lines 12 and 13 compute the tf matrix. The <code>amax</code> command in numpy computes the maximum value of an array along an axis. In this case, we want the row maximum (the second axis, which has index 1 because we start counting from zero). We want to divide each row of tf by its maximum. Numpy can divide matrices component-by-component if their shapes match. Alas, <code>term_count</code> is an <img src="https://latex.codecogs.com/png.latex?m%20%5Ctimes%20n"> matrix and <code>wordmax</code> is a vector of length <img src="https://latex.codecogs.com/png.latex?m">. But no matter; the array <code>wordmax[:,None]</code> converts this vector to the appropriate matrix. Essentially, <code>:</code> in the first index means the rows come from the whole vector, and <code>None</code> in the second index means to extend the rows as far to the right as necessary.</p>
<p>The fact that this method is implemented with numpy-only functions, and not by walking the array in a python loop, makes it run faster.</p>
<p>Here is the idf propery:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode numberSource python numberLines code-with-copy"><code class="sourceCode python"><span id="cb3-1"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">@property</span></span>
<span id="cb3-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> idf(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>):</span>
<span id="cb3-3">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""inverse document frequency matrix</span></span>
<span id="cb3-4"></span>
<span id="cb3-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    return a vector IDF, where</span></span>
<span id="cb3-6"></span>
<span id="cb3-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    IDF[j] = log((# of posts)/(1 + # of posts containing word j ))</span></span>
<span id="cb3-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    """</span></span>
<span id="cb3-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._idf <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">is</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>:</span>
<span id="cb3-10">        tf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.tf</span>
<span id="cb3-11">        nposts,nwords <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> tf.shape</span>
<span id="cb3-12">        term_incidence <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> numpy.ceil(tf)</span>
<span id="cb3-13">        num_containing <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> numpy.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>(term_incidence,axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb3-14">        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._idf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> numpy.log(nposts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>num_containing))</span>
<span id="cb3-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._idf</span></code></pre></div></div>
<p>To count the number of posts containing a word, I rounded up the term-frequency matrix. Since term frequency is between zero and one, and positive only if the term appears in the post, this will return a matrix of zeros and ones. Then summing the <em>columns</em> will give a (row) vector of the post-count per word.</p>
<p>With tf and idf we compute tf-idf:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode numberSource python numberLines code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">@property</span></span>
<span id="cb4-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> tfidf(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>):</span>
<span id="cb4-3">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""the tf-idf matrix</span></span>
<span id="cb4-4"></span>
<span id="cb4-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    tfidf[i,j] = TF[i,j] * IDF[j]</span></span>
<span id="cb4-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    """</span></span>
<span id="cb4-7">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._tfidf <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">is</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>:</span>
<span id="cb4-8">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># compute it!</span></span>
<span id="cb4-9">        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._tfidf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.tf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.idf[<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>,:]</span>
<span id="cb4-10">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._tfidf</span></code></pre></div></div>
<p>Remember that <code>self.tf</code> and <code>self.idf</code> are methods, but because of the <code>@property</code> decorator, we get to pretend that they are properties. Otherwise we would need to write <code>self.tf()</code> and so on.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode numberSource python numberLines code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">@property</span></span>
<span id="cb5-2"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> dc(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>):</span>
<span id="cb5-3">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""the document cosine similarity matrix"""</span></span>
<span id="cb5-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._dc <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">is</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">None</span>:</span>
<span id="cb5-5">        tfidf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.tfidf</span>
<span id="cb5-6">        result <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> numpy.dot(tfidf,numpy.transpose(tfidf))</span>
<span id="cb5-7">        d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> numpy.diagonal(result)</span>
<span id="cb5-8">        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._dc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> result<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>numpy.sqrt(numpy.outer(d,d))</span>
<span id="cb5-9">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>._dc</span></code></pre></div></div>
<p>Line 6 is where we compute <img src="https://latex.codecogs.com/png.latex?AA%5ET">. We then extract its diagonal vector and form the outer product with <span class="title-ref">numpy.outer</span>. Again, a pure numpy implementation means a fast execution.</p>
<p>The last method to implement sets the related posts for each post.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode numberSource python numberLines code-with-copy"><code class="sourceCode python"><span id="cb6-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> set_related(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>,site):</span>
<span id="cb6-2">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">""" set the top related posts for each post"""</span></span>
<span id="cb6-3">    dcs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.dc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> numpy.identity(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.dc.shape[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb6-4">    indices_sorted <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> dcs.argsort(axis<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)[:,<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.num_related:][:,::<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]</span>
<span id="cb6-5">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i,post <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">enumerate</span>(site.posts):</span>
<span id="cb6-6">        post.related <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb6-7">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> r <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> indices_sorted[i,:]:</span>
<span id="cb6-8">            post.related.append(site.posts[r])</span></code></pre></div></div>
<p>The array <code>dcs</code> in line 3 subtracts one from every diagonal entry of <code>self.dc</code>. Notice that <code>self.dc</code> is going to have ones on the diagonal, because it measures the correlation of each post with itself. For purposes of displaying interesting related content, it doesn’t help to link to the original document. Subtracting the identity matrix replaces the ones with zeros. This forces each post’s self-correlation value to the minimum instead of the maximum, ensuring the post will not be counted as related to itself.</p>
<p>The numpy function <code>argsort</code> returns the indices of the array in increasing order of their corresponding values (as opposed to <code>sort</code> which would just sort the values.) The property <code>self.num_related</code> is just a config value that stores how many posts to return. So line 4 sorts each row by index of increasing value, selects the <code>self.num_related</code> rightmost columns, then reverses the columns. Therefore <code>indices_sorted</code> has a row for each post, <code>self.num_related</code> columns, and the values are the post indices of the most related posts (not including the post itself.)</p>
<p>The for loop in lines 5 through 8 just walks the list of posts, creating a list property <code>self.related</code>, and adding a reference to each related post.</p>
<p>Of course, whether this information appears in the presented page is up to the post’s template. That is a post for another day. Suffice it to say the <a href="http://www.makotemplates.org/">mako</a> templating engine can handle this easily.</p>
</section>
<section id="natural-language-processing" class="level1">
<h1>Natural language processing</h1>
<p>I lied a bit when I said that <code>post.meta('words')</code> was a list of “words” in the post, and that <code>site.allwords</code> was a list of all words in the site. For purposes of relating documents, we don’t want to distinguish between words like <em>python</em>, <em>python’s</em>, or <em>pythonic</em>.</p>
<p>Enter python’s <a href="http://www.nltk.org/">Natural Language Toolkit (NLTK)</a>. NLTK contains many, many resources for processing texts. One such resource is a package of <em>stemmers</em>, which truncate a word to its “stem”. If one word is just a form of another word, the two words should have the same stem.</p>
<p>Here is a quick example:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;&gt;&gt;</span> <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> nltk</span>
<span id="cb7-2"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;&gt;&gt;</span> s <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> nltk.stem.SnowballStemmer(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"english"</span>)</span>
<span id="cb7-3"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;&gt;&gt;</span> [s.stem(word) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> word <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"python"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"python's"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pythonic"</span>]]</span>
<span id="cb7-4">[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'python'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'python'</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'python'</span>]</span></code></pre></div></div>
<p>The <code>set_words</code> methods applies this stemming first to shorten the word list and consolidate forms:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode numberSource python numberLines code-with-copy"><code class="sourceCode python"><span id="cb8-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> set_words(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>,site):</span>
<span id="cb8-2">    stemmers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{}</span>
<span id="cb8-3">    default_stemmer<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>SnowballStemmer(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.stemmer_map[site.default_lang])</span>
<span id="cb8-4">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> post <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> site.posts:</span>
<span id="cb8-5">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">try</span>:</span>
<span id="cb8-6">            lang <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> post.lang</span>
<span id="cb8-7">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">except</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">AttributeError</span>:</span>
<span id="cb8-8">            lang <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> site.default_lang</span>
<span id="cb8-9">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">try</span>:</span>
<span id="cb8-10">            stemmer<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>stemmers[lang]</span>
<span id="cb8-11">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">except</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">KeyError</span>:</span>
<span id="cb8-12">            stemmers[lang] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> SnowballStemmer(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.stemmer_map[lang])</span>
<span id="cb8-13">            stemmer<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>stemmers[lang]</span>
<span id="cb8-14">        words<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[]</span>
<span id="cb8-15">        fulltext <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> post.meta(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'title'</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> post.text(strip_html<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb8-16">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> word <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> word_tokenize(fulltext):</span>
<span id="cb8-17">            words.append(stemmer.stem(word))</span>
<span id="cb8-18">        post.meta[lang][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'words'</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> words</span>
<span id="cb8-19">        <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.allwords.extend(words)</span>
<span id="cb8-20">    <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.allwords <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">list</span>(unique_everseen(<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">self</span>.allwords))</span></code></pre></div></div>
<p>Lines 5 through 13 produce a stemmer object depending on the post’s language. (A potential bug is that not all languages supported by Nikola have SnowballStemmers. Also, this probably should be a factory method to clean up the code.)</p>
<p><code>word_tokenize</code> is an NLTK function that splits text into tokens like words, but smartly. You might wonder why not do a simple <code>split</code> on the string by whitespace or some other regular expression. Then you realize this is probably harder than it looks at first glance, and remember that someone has probably already solved this problem. With <code>word_tokenize</code>, bits like punctuation get split off, and contractions are split into separate tokens. So “doesn’t?” becomes <code>["does","n't","?"]</code>.</p>
<p>So we tokenize each post’s text, stem each word, and add the list to the post as a property (not sure it needs to be in the <code>meta</code> dictionary). We extend the “master” word list with these words. Once finished, we apply <code>unique_everseen</code> from the <code>more_itertools</code> package to remove repated words from the master list. (We do <em>not</em> want to do this for the individual posts; if they contain a word several times that is going to increase term frequency.)</p>
</section>
<section id="next-steps" class="level1">
<h1>Next steps</h1>
<p>This post took about as long to write as the plugin! And now that I’ve done a full exegesis of my code, I realize that I could improve it in many ways. Not just adding features, but by cleanup and streamlining.</p>
<p>Right now this plugin is a config plugin, which means it generates the related posts each time the site builds. But the underlying data only changes every time a post is updated. So perhaps this is better implemented as a Task plugin, which depends on the post timeline. For that I need to learn more about the <a href="https://pydoit.org/">doit</a> package for python.</p>
<p>Nikola has support for posts in several languages, and even translated versions of posts. Before merging any of this work into Nikola it would have to handle that, at least partially. NLTK has stemmers for several languages (though not as many as Nikola supports). Now that I think of it, as long as the post’s <code>words</code> property contained the words, stemmed in the appropriate language, and the plugin’s <code>allwords</code> property contained all wordstems used in all languages, the matching algorithm should naturally match posts in each language to posts in the same language.</p>
<p>Inverse document frequency takes care of common words like <em>the</em>, <em>an</em>, <em>of</em>, etc., by giving them a small coefficient. However, NLTK knows how to do this too. Stemmers can be configured to simply ignore “stop words” such as these. It might make the tf-idf matrix a little smaller to use this feature.</p>
<p>I’ve also realized that numpy can be used with an object-oriented approach. I can replace lines like <code>numpy.dot(tfidf,numpy.transpose(tfidf))</code> with <code>numpy.dot(tfidf,tfidf.transpose())</code>. That might be the more pythonic approach.</p>
<p>Weights could be introduced, as they are in the inspiring jekyll plugin. But as of now I’m not dissatisfied with the results I’m getting with uniform weights.</p>
<p>It would be fun to add the degree of correlation to the match, and maybe pass it to HTML as a <code>data</code> attribute.</p>


</section>

 ]]></description>
  <category>computing</category>
  <category>nikola</category>
  <category>python</category>
  <category>linear algebra</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-07-11-document-correlation-with-nikola-nltk-and-numpy/</guid>
  <pubDate>Mon, 11 Jul 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Math with Bad Drawings: What Students See When They Look at Algebra</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-06-23-math-with-bad-drawings-what-students-see-when-they-look-at-algebra/</link>
  <description><![CDATA[ 





<p>Ben Orlin is back at it again with an <a href="https://mathwithbaddrawings.com/2016/06/22/what-students-see-when-they-look-at-algebra/">installment of Math With Bad Drawings</a>. This one is about how students view algebra.</p>
<figure class="img-responsive, img-thumbnail figure">
<img src="https://mathwithbaddrawings.files.wordpress.com/2016/06/20160620170224_00003.jpg?w=1164" class="img-responsive, img-thumbnail figure-img">
</figure>
<p>Read the whole thing for context.</p>
<p>I don’t know if it’s years of experience or a literature review that produced his “cases.” I do know (and this is my experience talking) that’s he’s spot on.</p>
<p>I would add a case from precalculus that’s hard for me: students struggle with the idea of <em>function</em>. Here are some bad drawings of my own.</p>
<figure class="img-responsive, img-thumbnail figure">
<img src="http://svgur.com/i/6X.svg" class="img-responsive, img-thumbnail figure-img">
</figure>
<p>A function is a relation between two sets, which has a unique “output” for each “input.” Mathematicians tend to think of a function as a kind of machine which converts elements in one set (for instance, numbers) to elements in another.</p>
<figure class="img-responsive, img-thumbnail figure">
<img src="http://svgur.com/i/7G.svg" class="img-responsive, img-thumbnail figure-img">
</figure>
<p>My experience with students is that a function is a graph, and <img src="https://latex.codecogs.com/png.latex?a"> and <img src="https://latex.codecogs.com/png.latex?b"> arbitrary numbers on the <img src="https://latex.codecogs.com/png.latex?x">- and <img src="https://latex.codecogs.com/png.latex?y">-axis.</p>
<figure class="img-responsive, img-thumbnail figure">
<img src="http://svgur.com/i/6J.svg" class="img-responsive, img-thumbnail figure-img">
</figure>
<p>In general, graphs are not a bad way to think about functions, with a few caveats. One is that the independent axis is too often assumed to be “time.” It’s hard to think of supply and demand depending on price when you only think of functions as depending on time.</p>
<p>Another is that your typical picture of a function may not be generic enough. I’ve drawn the graph of the function <img src="https://latex.codecogs.com/png.latex?f(x)%20=%20x%5E2"> because that is what most students think of when they are asked what a function is: “you know, like <img src="https://latex.codecogs.com/png.latex?x%5E2">.” Another student might draw a squiggle, which is more general, but still continuous. If all your mental models of functions are continuous, it’s hard to work with functions that could be discontinuous. One of my grad school profs would say this over and over again: “Remember, if it’s an <img src="https://latex.codecogs.com/png.latex?L%5E1"> function, it’s <strong>probably discontinuous everywhere</strong>” (accompanied by wild flapping of his arms to mimic the graph of such a function).</p>
<p>You may point out that this image is <em>wrong</em> in that the point <img src="https://latex.codecogs.com/png.latex?(a,b)"> is not on the graph of <img src="https://latex.codecogs.com/png.latex?f">. That is, this picture does not illustrate the statement <img src="https://latex.codecogs.com/png.latex?f(a)=b">. I agree, and my point is that many students think of functions as graphs <em>without connecting the points on the graph to values of the function</em>. For these students, their one good framework is flawed.</p>
<p>When teaching, I try to emphasize these connections as much as possible. Functions are graphs, machines, rules, and so forth. I do “air graph” functions with my arms. Luckily in calculus most functions are piecewise <img src="https://latex.codecogs.com/png.latex?C%5E%5Cinfty">.</p>



 ]]></description>
  <category>teaching</category>
  <category>comic</category>
  <category>funny</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-06-23-math-with-bad-drawings-what-students-see-when-they-look-at-algebra/</guid>
  <pubDate>Thu, 23 Jun 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Cloning a git workshop</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-06-15-cloning-a-git-workshop/</link>
  <description><![CDATA[ 





<div class="post-intro">
<p>When I was at the <a href="http://aimath.org/pastworkshops/mathbookxml.html">MathBookXML workshop</a> at <a href="https://aimath.org/">AIM</a> in April, <a href="https://buzzard.ups.edu/">Rob Beezer</a> gave us a quick two-hour workshop on <code>git</code> and <a href="https://github.com/">github</a>. Although I had been using it to manage some of my projects, I couldn’t quite understand how it worked in a collaborative environment (which is, after all, what it is chiefly designed for). After a couple of hours, I could finally say that I got git.</p>
<p>At least enough to teach my coworkers. That’s what I did today. I made a fork of Rob’s <a href="https://github.com/BooksHTML/gitpractice">gitpractice</a> repository, and we all practiced the development process.</p>
</div>
<p>Here is the basic flow:</p>
<ol type="1">
<li><p>In github, fork the central repository to your own account.</p></li>
<li><p>Clone your personal fork to your own machine. The url of your fork can be copied from the repository page on github. In a terminal window run:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git clone <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>forkurl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div></li>
<li><p>Create a branch of the repository on your clone of the fork, and switch to that branch.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git branch <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>branchname<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb2-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git checkout <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>branchname<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div>
<p>Creating a branch does not automatically switch to it! If you want to do both at the same time, at the expense of a more cryptic command, run</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git checkout <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-b</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>branchname<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div></li>
<li><p>Edit files and commit changes to the branch.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git add <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>changed files<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb4-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git commit <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-m</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"&lt;message&gt;"</span></span></code></pre></div></div>
<p>The message goes into the repository’s log. There are differing conventions on commit message styles. Rob’s advice is to write in sentence predicates (verb + object), with the verb in <em>imperative mood</em>. So something like <code>use display style by default</code> instead of <code>configured to use display style by default</code>. Another convention would be to start with a verb in <em>past tense</em>, but I must admit, after trying Rob’s suggestion for a while, I find it more succinct and easier to write good messages.</p></li>
<li><p>Push changes to your fork on github.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git push origin <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>branchname<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div>
<p>In many development environments the changes would be merged into the local master branch first, and then pushed to origin. But here we plan to have this branch merged into the central repository, which will eventually reach our local and fork.</p>
<p>Going back to github you can see that a new branch has been created.</p></li>
<li><p>Submit a pull request to have the central repository merge (or “pull”) the changes on your branch.</p></li>
</ol>
<p>Everybody got it done. You could say we successfully cloned the workshop. Or is it forked?</p>
<p>The “exciting” part was that one of the pull requests created a conflict. So I got to demo that as the master of the central or base repository. The process is:</p>
<ol type="1">
<li><p>Clone the central repository to a local machine</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git clone <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>baseurl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div></li>
<li><p>Create and switch to a temporary branch. The branch can be called anything, but github suggests <code>username-theirbranchname</code></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb7-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git checkout <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-b</span> newbranch</span></code></pre></div></div></li>
<li><p>Merge the changes from the fork branch (the one initiating the pull request) into the temporary branch (which has been checked out already).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb8-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git merge <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>forkurl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span>forkbranch<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span></span></code></pre></div></div></li>
<li><p>Checkout the master branch and merge in the temporary branch.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb9-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git checkout master</span>
<span id="cb9-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">$</span> git merge newbranch</span></code></pre></div></div>
<p>This recreates the conflict, only now between branches in the same repository.</p></li>
<li><p>Fix conflicts and push up to github.</p></li>
</ol>
<p>I wrote up my workshop script (again, stolen from Rob) into the repository’s <code>README.md</code> file. I also created a <a href="../../../github.com/nyumathclinic">new organization</a> and moved my repository over to it.</p>
<div class="credits">
<p><a href="https://flic.kr/p/baMxbP">Image</a> by Pete Ashton via Flickr (<a href="https://creativecommons.org/licenses/by-nc/2.0/">CC-BY-NC</a>)</p>
</div>



 ]]></description>
  <category>computing</category>
  <category>git</category>
  <category>github</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-06-15-cloning-a-git-workshop/</guid>
  <pubDate>Wed, 15 Jun 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Adding a category menu to Nikola</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-06-07-adding-a-category-menu-to-nikola/</link>
  <description><![CDATA[ 





<p>I have been obsessing about <a href="http://getnikola.com/">Nikola</a> lately. I wanted to add a “categories” widget to the navigation menu. It took me three tries but I finally figured out a pretty decent way to do it.</p>
<p>Nikola is just a pile of plugins, and its build process is derived from <a href="http://pydoit.org/">doit</a>. There are many ways to plug or hook into the building process. I pored over the docs, especially the section on <a href="https://getnikola.com/extending.html">Extending Nikola</a>.</p>
<p>One twist to my problem was that I wanted to put the count of posts per category in the menu. Seems like a nice touch, and the theme I am adapting has that feature. But the <code>NAVIGATION_LINKS</code> configuration variable only allows menus that have <code>(link,name)</code> tuples in them. No way to pass extra text to the template.</p>
<p>Then I thought I could do the whole thing in the page templates. There are lots of variables passed to the template. If the site itself were passed, I could have done that. Alas, not so.</p>
<p>My first real effort was to create a Task plugin that generated the category menu separately. The plan was to render a snippet of HTML that I could include in any page template. The snippet generation worked, but then the templating methods slapped <code>&lt;html&gt;</code> and <code>&lt;body&gt;</code> tags around the whole thing. Not what I wanted! I either had to filter off those extra tags, go a level deeper into the site object, or find another way.</p>
<p>Then I went back to the idea of a Config plugin, that put the category links in a submenu of <code>NAVIGATION_LINKS</code>. Instead of <span class="title-ref">(link,name)</span> tuple, I added tuples of the form <code>(link,name,count)</code>. In templates that were not aware of this extra struture, I figured that the extra data would be ignored as the templating system walked the list of links. Nope, I got a <code>Too many values to unpack</code> error. So this plugin breaks all existing page templates.</p>
<p>What if I passed the count to the template in a failsafe way? Rather than as a tuple, I tried <em>appending</em> the post count to the category link in the query string. So rather than <code>('/category/cat_foo.html','foo',3)</code>, I passed <code>('/category/cat_foo.html?count=3','foo')</code>. Then templates could check for the existence of this count key in the query string, strip it off, and use it to format the category menu. Templates that didn’t know to check for this would still work, having meaningless query strings attached to the category URLS.</p>
<p>It worked! Except I started struggling with the next step of putting the category menu where I wanted it. My plugin was <em>appending</em> to <code>site.NAVIGATION_LINKS</code>. That list (actually a tuple itself) is rendered into the navbar in order, meaning the category menu would go at the end. I didn’t want it to appear last in the navbar. So I started rewriting the template to walk the list of navigation links and select the category menu to put it first. Then to render the other links, I would need to rewalk the list, skipping the category menu.</p>
<p>At this point I realized that I was yet again trying to put a square peg in a round hole. I didn’t want to add the category menu to <code>site.NAVIGATION_LINKS</code>—the data I wanted to add didn’t fit there, and once it was there I didn’t want it treated like the rest of the navigation links. I needed to pass the category menu as a separate bit of data to the template.</p>
<p>Finally, after reading through the source code and <code>conf.py</code> one more time, I found was I was looking for. The <code>site.GLOBAL_CONTEXT</code> dictionary can hold whatever you want, and <em>it gets passed to all templates</em>. So really I just needed to pass whatever data I wanted to <code>site.GLOBAL_CONTEXT['CATEGORY_MENU']</code>. I gave it a list of 3-tuples <code>(link,count,name)</code>. Then I adapted the page templates to put this category menu exactly where I wanted in the navbar.</p>
<p>This is an example where the answer is obvious once you think about the problem for several days. If I were a real programmer I probably would have gotten it done a lot quicker. But I did do something that a real programmer would: I committed my plugin to a <a href="https://github.com/leingang/plugins/tree/category_menu/v7/category_menu">github repo</a>. It needs some love before I am ready to submit a pull request, but it gets the job done for now.</p>



 ]]></description>
  <category>blog</category>
  <category>python</category>
  <category>nikola</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-06-07-adding-a-category-menu-to-nikola/</guid>
  <pubDate>Tue, 07 Jun 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Problem solving and algorithms</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-05-31-problem-solving-and-algorithms/</link>
  <description><![CDATA[ 





<p>This evening at dinner my 9-year-old son talked about a problem he had been working on for math homework.</p>
<blockquote class="blockquote">
<p>Ben and Cole have 36 toy cars. Ben has 8 more than Cole. How many does Ben have?</p>
</blockquote>
<p>We had some fun discussing solutions to this problem, and a few wrong answers.</p>
<p>First, the wrong answer: more than one person at the table blurted out that Ben had 28 cars. Why? Because <img src="https://latex.codecogs.com/png.latex?36-8=28">. The logic behind this solution comes from skimming the problem: the only numbers are <img src="https://latex.codecogs.com/png.latex?36"> and <img src="https://latex.codecogs.com/png.latex?8">, and the word <em>more</em> usually indicates subtraction.</p>
<p>But this doesn’t satisfy the original problem. If Ben has 28 cars, Cole has 20, and the two together have 48 cars, not 36 as the problem demands. So we’ve learned it can’t be 20, and that we can’t read word problems without reading every word.</p>
<p>In the assignment, my son was supposed to use the “guess-check-revise” method. His first guess was <img src="https://latex.codecogs.com/png.latex?18">. This is obviously not a solution because Ben needs to have 8 more. So he kept increasing Ben’s number and decreasing Cole’s until he found a difference of 8.</p>
<p>My daughter, age 13, is in pre-algebra. Here was her approach, which you might call combinatorial. Take the eight “more” cars that Ben has and set them aside. There are <img src="https://latex.codecogs.com/png.latex?36-28=8"> cars remaining (“See?” says the skimmer. “I told you we had to do that.”) They have to be divided evenly between Ben and Cole, since all the inequity has already been accounted for. So of these 28, Ben and Cole each own 14. Therefore Ben has <img src="https://latex.codecogs.com/png.latex?14+8=22"> and Cole has just the <img src="https://latex.codecogs.com/png.latex?14">.</p>
<p>That shows good number sense. By next year, she will probably solve the problem this way: let <img src="https://latex.codecogs.com/png.latex?x"> be Cole’s car count. Then Ben’s car count is <img src="https://latex.codecogs.com/png.latex?x+8">. Add the two (<img src="https://latex.codecogs.com/png.latex?2x+8">) and the total is <img src="https://latex.codecogs.com/png.latex?36">. Therefore <img src="https://latex.codecogs.com/png.latex?2x+8=36%20%5Cimplies%20x=14%20%5Cimplies%20x+8%20=%2022">. This is totally efficient, and if you read it carefully, mimics in mathematical language the argument from the previous paragraph. On the other hand, the price of algebraic efficiency is that it’s easy to lose number sense. So I hope she doesn’t forget her seventh-grade techniques as she learns her eighth-grade ones.</p>
<p>My solution was the worst. I immediately jumped to</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Baligned%7D%0A%5Cbegin%7Baligned%7D%0A%20%20%20%20x+y%20&amp;=%2036%20%5C%5C%0A%20%20%20%20x-y%20&amp;=%208%0A%5Cend%7Baligned%7D%0A%5Cend%7Baligned%7D"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?x"> is Ben’s car count and <img src="https://latex.codecogs.com/png.latex?y"> is Cole’s. But I couldn’t solve two equations in two variables in my head while eating chicken and couscous. So I gave up.</p>
<p>I found it interesting that my approach was the most sophisticated but also the most technically difficult. The kids haven’t been boxed in by the standard algorithms yet. Common Core emphasizes procedural flexibility and choosing an appropriate solution strategy among many. I think this is a good thing.</p>
<p>Many of my calculus students arrive assuming that each problem has a unique best solution method, which needs to be shown them before the problem can be solved. But one of the findings detailed in <a href="https://www.amazon.com/Make-Stick-Science-Successful-Learning/dp/0674729013?ie=UTF8&amp;*Version*=1&amp;*entries*=0">Make it Stick</a> by Brown, Roediger, and McDaniel is that students learn better when the attempt a problem before being shown its solution. And having many strategies to choose from allows students to find their own solutions.</p>
<p>Epilogue: Please do not get the impression that all of our dinner conversations at home are about math! I was just lucky on this particular evening.</p>
<div class="credits">
<p><a href="https://flic.kr/p/e5epEi">Image</a> by Joe Haupt via flickr (<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>)</p>
</div>



 ]]></description>
  <category>math</category>
  <category>education</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-05-31-problem-solving-and-algorithms/</guid>
  <pubDate>Tue, 31 May 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>A characteristic function for analysis experience</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-05-23-a-characteristic-function-for-analysis-experience/</link>
  <description><![CDATA[ 





<p>(This is a based on a Facebook post I made a couple of days ago.)</p>
<p>Here’s a case study: a student with a very irregular course history insists they have at one point in their college career learned analysis. What questions would you ask the student to verify this?</p>
<p>In analysis, a <em>characteristic function</em> of a set determines whether points in a space are in the given set. To put it more formally, if <img src="https://latex.codecogs.com/png.latex?X"> is a set and <img src="https://latex.codecogs.com/png.latex?E"> a subset of <img src="https://latex.codecogs.com/png.latex?X">, the characteristic function of <img src="https://latex.codecogs.com/png.latex?E"> is the set</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Baligned%7D%0A%5Cchi_E(x)%20=%20%5Cbegin%7Bcases%7D%201%20&amp;%20%5Ctext%7Bif%20$x%5Cin%20E$%7D%20%5C%5C%200%20&amp;%20%5Ctext%7Botherwise%7D%20%5C%5C%20%5Cend%7Bcases%7D%0A%5Cend%7Baligned%7D"></p>
<p>If <img src="https://latex.codecogs.com/png.latex?X"> is the set of all students, and <img src="https://latex.codecogs.com/png.latex?E"> is the subset of students who have taken analysis, I could just apply <img src="https://latex.codecogs.com/png.latex?%5Cchi_E"> to the student and find the value. But this is no simple matter. (Although <img src="https://latex.codecogs.com/png.latex?%5Cchi_E"> is an example of a <em>simple function</em> in measure theory.)</p>
<p>In our analysis course, students learn formal properties like the <img src="https://latex.codecogs.com/png.latex?%5Cepsilon">, <img src="https://latex.codecogs.com/png.latex?%5Cdelta"> definition of a limit, and the integral as a limit of Riemann sums. But a student who had taken this course long ago may have forgotten those precisely, or claim to have forgotten them. I didn’t want to ask a question with a unique answer.</p>
<p>Here are some suggested questions I got that I quite liked:</p>
<ul>
<li><strong>What’s so special about the real numbers?</strong> If a student said that the real numbers were complete, that would be good evidence of analysis exposure. Or they might mention the least upper bound property. Or their uncountability. Someone without analysis could still answer the question, but they might say something like “they go on and on forever.”</li>
<li><strong>What’s the difference between open and closed sets?</strong> A student could say that closed sets contain their limit points. From there we could go into a discussion of some examples: discrete sets, closed intervals, etc. A less-experienced student might instead say that closed sets are defined by less-than-or-equal-to or greater-than-or-equal-to inequalities.</li>
<li><strong>Give an example of a function which is not continuous at a point, and show why it is not continuous.</strong> Students learn the notion of continuity in calculus. Someone who took calculus could probably draw the graph of a function with different left- and right-sided limits at a point. How they answered the “show” part of the question would determine if they knew how to talk about the limit concept rigorously.</li>
</ul>
<p>In the case that inspired this post, I got all the good answers far too late. Instead, I emailed the head of the department of the students’ previous school. The information she provided was definitive in deciding whether the student had learned analysis. But at least I know what to do next time.</p>
<div class="credits">
<p><a href="https://flic.kr/p/c8AUK5">Image</a> by Bryon Barrett via Flickr (<a href="https://creativecommons.org/licenses/by-nc-nd/2.0/">CC-BY-NC-ND</a>)</p>
</div>



 ]]></description>
  <category>advising</category>
  <category>math</category>
  <category>education</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-05-23-a-characteristic-function-for-analysis-experience/</guid>
  <pubDate>Mon, 23 May 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>An alternative proof of the product rule</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-05-19-an-alternative-proof-of-the-product-rule/</link>
  <description><![CDATA[ 





<div class="getty embed image" style="background-color:#fff;display:inline-block;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#a7a7a7;font-size:11px;width:100%;max-width:507px;">
<div style="padding:0;margin:0;text-align:left;">
<a href="http://www.gettyimages.com/detail/97762204" target="_blank" style="color:#a7a7a7;text-decoration:none;font-weight:normal !important;border:none;display:inline-block;">Embed from Getty Images</a>
</div>
<div style="overflow:hidden;position:relative;height:0;padding:66.666667% 0 0 0;width:100%;">
<iframe src="//embed.gettyimages.com/embed/97762204?et=J3CN1hpzQiRmjasVA7MUbA&amp;viewMoreLink=on&amp;sig=QaV_UJXnGDg6NJnGl3bR94AjW3xdQSJijJ5wyAJtIEc=" width="507" height="338" scrolling="no" frameborder="0" style="display:inline-block;position:absolute;top:0;left:0;width:100%;height:100%;margin:0;">
</iframe>
</div>
<p style="margin:0;">
</p>
</div>
<p>Piotr Josevich wrote a short <a href="http://dx.doi.org/10.4169/amer.math.monthly.123.5.470">article</a> (this post will probably end up longer than it) in the American Mathematical Monthly about an alternative proof of the product rule. It requires nothing more than the generalized power rule for <img src="https://latex.codecogs.com/png.latex?n=2"> and <a href="http://en.wikipedia.org/wiki/FOIL_method">FOIL</a>.</p>
<p>First, let <img src="https://latex.codecogs.com/png.latex?u"> be differentiable at <img src="https://latex.codecogs.com/png.latex?a">. Let <img src="https://latex.codecogs.com/png.latex?v(x)%20=%20u(x)%5E2">. Then</p>
<p><img src="https://latex.codecogs.com/png.latex?%5Cbegin%7Baligned%7D%0A%5Cbegin%7Baligned%7D%0Av'(a)%20&amp;=%20%5Clim_%7Bx%5Cto%20a%7D%20%5Cfrac%7Bv(x)-v(a)%7D%7Bx-a%7D%20%5C%5C%0A%20%20%20%20%20%20&amp;=%20%5Clim_%7Bx%5Cto%20a%7D%20%5Cfrac%7Bu(x)%5E2%20-%20u(a)%5E2%7D%7Bx-a%7D%20%5C%5C%0A%20%20%20%20%20%20&amp;=%20%5Clim_%7Bx%5Cto%20a%7D%20%5Cfrac%7B(u(x)+u(a))(u(x)-u(a))%7D%7Bx-a%7D%20%5C%5C%0A%20%20%20%20%20%20&amp;=%20%5Clim_%7Bx%5Cto%20a%7D%20(u(x)+u(a))%20%5Ccdot%20%5Clim_%7Bx%5Cto%20a%7D%5Cfrac%7Bu(x)-u(a)%7D%7Bx-a%7D%20%5C%5C%0A%20%20%20%20%20%20&amp;=%202%20u(a)%20u'(a)%0A%5Cend%7Baligned%7D%0A%5Cend%7Baligned%7D"></p>
<p>So, in general, the derivative of <img src="https://latex.codecogs.com/png.latex?u%5E2"> is <img src="https://latex.codecogs.com/png.latex?2u%20u">.</p>
<p>Now, let <img src="https://latex.codecogs.com/png.latex?f"> and <img src="https://latex.codecogs.com/png.latex?g"> be differentiable. Let <img src="https://latex.codecogs.com/png.latex?u%20=%20f+g"> and <img src="https://latex.codecogs.com/png.latex?v%20=%20u%5E2">. Then</p>
<p><img src="https://latex.codecogs.com/png.latex?v'%20=%202%20u%20u'%20=%202%20(f+g)(f'+g')%20=%202(ff'%20+%20fg'%20+%20gf'%20+%20gg')"></p>
<p>On the other hand, <img src="https://latex.codecogs.com/png.latex?v%20=%20(f+g)%5E2%20=%20f%5E2%20+%202fg%20+%20g%5E2">, so</p>
<p><img src="https://latex.codecogs.com/png.latex?v'%20=%202ff'%20+%202(fg)'%20+2gg'"></p>
<p>Therefore, after canceling the factor of <img src="https://latex.codecogs.com/png.latex?2"> from each,</p>
<p><img src="https://latex.codecogs.com/png.latex?ff'%20+%20fg'%20+%20gf'%20+%20gg'%20=%20ff'%20+%20(fg)'%20+%20gg'"></p>
<p>Finally, after canceling <img src="https://latex.codecogs.com/png.latex?ff'"> and <img src="https://latex.codecogs.com/png.latex?gg'"> from both sides, we have</p>
<p><img src="https://latex.codecogs.com/png.latex?(fg)'%20=%20fg'%20+%20gf'"></p>
<p>I like this proof. I’m not sure it’s better than the typical “add and subtract the same thing” trick that’s often used. Both have a little bit of hocus-pocus in them.</p>
<p>When I teach the product rule I ask this question: Say you’re working for an hourly wage (like, in a pizza parlor or burger chain), and you want to make more money. How can you do that? The answers usually come from the class:</p>
<ol type="1">
<li>Work more hours.</li>
<li>Get a raise.</li>
</ol>
<p>Each of these will change your income independently. If you work more hours, your income goes up by the change in hours worked times your wage. If you get a raise, your income goes up by the hours worked times the change in your wage. If you do <em>both</em>, well, you get both!</p>
<p>In this story, <img src="https://latex.codecogs.com/png.latex?f"> is the hours worked and <img src="https://latex.codecogs.com/png.latex?g"> is the wage. Their product <img src="https://latex.codecogs.com/png.latex?fg"> is the income. The change in income (<img src="https://latex.codecogs.com/png.latex?(fg)'">) is the sum of the change in hours times the original wage (<img src="https://latex.codecogs.com/png.latex?f'g">) and the change in wage times the original hours worked (<img src="https://latex.codecogs.com/png.latex?fg'">).</p>



 ]]></description>
  <category>calculus</category>
  <category>math</category>
  <category>product rule</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-05-19-an-alternative-proof-of-the-product-rule/</guid>
  <pubDate>Thu, 19 May 2016 00:00:00 GMT</pubDate>
</item>
<item>
  <title>NYU Commencement 2016</title>
  <link>https://www.matthewleingang.com/blog/archive/2016-05-18-nyu-commencement-2016/</link>
  <description><![CDATA[ 





<p>NYU’s university-wide commencement was today at Yankee Stadium. Although I am a Red Sox fan, I often go and I usually enjoy myself.</p>
<p>It was an adventure alone to get there. My NJTransit bus got stuck in the bottleneck where 495 comes off of the Turnpike. I got into Port Authority a half hour late and barely made it to Washington Square in time to run to my office, put on my robe, and get on the bus.</p>
<p>It takes about an hour to get from NYU to the stadium. I chatted with <a href="http://www.nyu.edu/life/diversity-nyu/diversity-resources/faculty-resources/postdoctoral-and-transition/fellows7.html">Rick Garcia</a>, an assistant professor and diversity fellow at the NYU Rory Myers College of Nursing. We swapped stories of outrageous things students have done, and wondering if they were innocent and unaware or playing us for fools (I’m pretty sure it’s some from each category).</p>
<p>Once there I met up with <a href="http://math.nyu.edu/~vbhat/">Vindya Bhat</a>, another one of the Clinical Faculty who I convinced to come along. We arrived at the deliveries entrance to the stadium, and we processed from the outfield entrance, along the warning track, and to our seats at third base.</p>
<p><a href="https://instagram.com/p/BFjYkdAOWVj/?taken-by=mleingang">View this photo on Instagram</a></p>
<p>All around us were students in violet robes, probably 15,000 of them: bachelor’s degree candidates, master’s, Ph.D.s, doctors, lawyers, dentists, and engineers. It’s easy to forget as one class passes through and another takes its place, that for these students this day is the most important of their lives so far.</p>
<p>Among the honorary degree recipients were Billy Crystal. He is a lifelong New Yorker and wore a Yankees cap with a tassel. It was not mentioned in his citation that in one of his best movies (When Harry Met Sally) he portrayed an alumnus of the University of Chicago.</p>
<p>John Lewis was also honored. He received a standing ovation from the students, and duly so. Another honoree was Hillary Margaret Marshall, who recently retired as chief justice of the Massachusetts Supreme Judicial Court. She made sure that her citation read that she decreed a Red Sox World Series championship this year.</p>
<blockquote class="blockquote">

</blockquote>
<div class="figure">
<div class="getty embed image" style="background-color:#fff;display:inline-block;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#a7a7a7;font-size:11px;width:100%;max-width:594px;">
<div style="padding:0;margin:0;text-align:left;">
<a href="http://www.gettyimages.com/detail/532153454" target="_blank" style="color:#a7a7a7;text-decoration:none;font-weight:normal !important;border:none;display:inline-block;">Embed from Getty Images</a>
</div>
<div style="overflow:hidden;position:relative;height:0;padding:66.666667% 0 0 0;width:100%;">
<iframe src="//embed.gettyimages.com/embed/532153454?et=CdwvNQO0TWBHFxZqxkStqg&amp;viewMoreLink=on&amp;sig=8_MHxjq_acabTJ67S5sj9u3NHx_6ESRUT9g_9lOp-Kc=&amp;caption=true" width="594" height="396" scrolling="no" frameborder="0" style="display:inline-block;position:absolute;top:0;left:0;width:100%;height:100%;margin:0;">
</iframe>
</div>
<p style="margin:0;">
</p>
</div>
</div>
<p>Andy Hamilton has been president of NYU for less than five months, but plays the part very well. In his address, he said:</p>
<blockquote class="blockquote">
<p>Before NYU I was head of Oxford, where we do our commencements a bit differently. It takes place in the 350-year-old <a href="">Sheldonian Theatre</a>. All faculty and degree candidates are in white tie. And the entire ceremony is conducted in Latin.</p>
<p>Today I am standing on second base in Yankee Stadium, where the last time Latin was spoken was when the pope said mass here. I can smell the popcorn and the hot dogs from the stands, I can hear the rumbling of the subway behind me, and I say to myself: there is no place I’d rather be.</p>
</blockquote>
<p>He said many other nice things, too, including advising the graduates to make the most of their inevitable setbacks. He shared the story of not getting tenure on his first review (For non-academic readers, this means you are fired and you have to start over someplace else). But he eventually got another position, made tenure and promotions, became head of the department, and went up the ladder.</p>
<p>It was about three hours from marching in to filing out, up the aisle, out the gate, and onto Jerome Street. We took the same shuttle bus back to NYU, which meant another hour in traffic. The other option would have been riding the subway in my regalia, which I’ve done and will probably do again next time. Along with wearing my Red Sox cap.</p>



 ]]></description>
  <category>NYU</category>
  <category>instagram</category>
  <guid>https://www.matthewleingang.com/blog/archive/2016-05-18-nyu-commencement-2016/</guid>
  <pubDate>Wed, 18 May 2016 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
