Printing a range of bytes from a specific line in a file

To read the first B bytes from the Nth line of a file using pipes in bash:

cat filename | head -N | tail -1 | head -c B

The first pipe takes the output of cat filename (which is simply a printout of filename) and feeds it as input to head -N which produces the first N lines of filename, the last line of which is produced by tail -1, and then the first B bytes are pulled out by head -c B.

So, to read from byte B1 to B2 (inclusive) on the Nth line:

cat filename | head -N | tail -1 | tail -c +B1 | head -c B2-B1

This is cheating a bit because you have to work out B2-B1 first. If you type it as-is you will not succeed. The +B1 bit in the second tail command tells it to work from the start of the file (normally tail counts backwards).

Or you could do it much more “easily” using sed and cut. To start, we get the Nth line of the file:

sed 'Nq;d' filename

Knowing nothing about sed, this took a while to understand. I’m still not entirely sure if my intuition is correct, but it goes as follows: sed scans the file line by line. The q command is triggered only on line N. On every other line, instead of printing the file, it doesn’t print (thanks to d), so we see nothing. When it gets to line N it quits, after printing the line, but before triggering d. Another way to print only line N is with

sed -n 'Np' filename

What happens here is that -n tells said not to print anything, while p says ‘print line N’. The difference between this and the previous one is that sed will continue to the end of the file, quietly not printing anything. That’s sort of a waste of time, so – as per usual – the less comprehensible version is faster.

And now we can simply do

sed 'Nq;d' filename | cut -b B1-B2

Where here B1-B2 can can be written literally, because cut takes a range as its argument.

We could have also used awk to extract a line, instead of sed:

awk 'NR==N' filename

I am particularly interested in learning sed though, so I’ll try to stick to sed solutions where possible.


Elementary Dota 2


Dota 2 is notorious for its unforgiving learning curve. The barrier to entry is admittedly high. There are currently 101 heroes in the game, each of which has four skills (each of which has four levels), and over a hundred items (many of which come with active abilities). In order to “know” Dota 2, you would need to be familiar with all of these. Some would argue that new players should essentially read a Dota 2 textbook before approaching the game, because lack of familiarity with skills/heroes/items can lead to death, which leads to losing, which leads to your team shouting at you in languages you don’t understand.

Frankly, that’s boring, and probably unnecessary. A lot of this knowledge can be obtained “on the job”, especially if you play with friends who already know the game (and are patient). That said, the first several times I played Dota 2 I was confused to the point of extreme frustration, so here is an introductory guide to Dota 2 – information which should make the first few games a little bit more pleasant for both you and your team.

Note! I’m assuming you already want to play Dota 2, but know nothing about it.

The game, in brief.
Dota 2 Ancients

In Dota 2, two teams of five players attempt to destroy their opponent’s “ancient”, which is just a building in their base. The ancient is defended by various structures such as towers which must be destroyed first. Each player controls a “hero” which has unique skills and attributes. The game largely revolves around the acquisition of experience points and gold, which are obtained by destroying enemy units and buildings, or neutral units. Gold is used to buy items, and experience points cause one’s hero to level up and become stronger. Basic.

Note! Levels are not persistent. Each game is self-contained.

The map.
Dota 2 has one map. It looks like this: (ingame minimap)
Dota 2 minimap
Each team inhabits one half of the map. The bottom-left half is for Radiant (“the good guys”) and the top-right is for Dire (“the bad guys”). The dividing line is the river. Map control and awareness are critical in Dota 2, and not accidentally walking into enemy territory is an important skill.

The map is divided into three “lanes” and one “jungle” on each side.

Top is easy for Dire and hard for Radiant, Bot(tom) is easy for Radiant and hard for Dire.
Top is easy for Dire and hard for Radiant, Bot(tom) is easy for Radiant and hard for Dire.

The red/green squares correspond to buildings, usually towers. These are quite powerful and attack nearby enemies. To reach the enemy base, one must destroy the enemy towers in a lane. Towers cannot be rebuilt. The jungle contains neutral units which can be killed for personal gain. The lanes have the following names:

  • Mid: surprisingly, in the middle.
  • Easy: this is the lane adjacent to one’s jungle (top for Dire, bottom for Radiant).
  • Hard/long: the other one (bottom for Dire, top for Radiant).

Team composition, and more about lanes.
There are five players per team. There are three lanes. What do? Almost always, it looks like this:

  • Mid: one hero.
  • Long lane: one hero, infrequently two. For this reason, long lane is often called “solo lane”.
  • Easy lane: two heroes, sometimes three. If there are three, it’s called a “trilane”.
  • Jungle: at most one hero.

The variation in this is due to differences between heroes and strategies. Not all heroes can be played in all positions (particularly jungle). This information is important to you, because every game starts with team selection, and not every combination of heroes actually works. Team selection is perhaps the most important aspect of the game, and a badly chosen team can spell ruin. New players are unlikely to have to make these decisions, but it is a crucial aspect of the game which one should be aware of.

So why these lane choices? Every thirty seconds, a wave of “creeps” spawn at the start of your lane, and walk towards the enemy base. Creeps are allied units which will fight enemies they encounter. Whenever enemies are killed near you, experience is shared between all allies, so for much of the start of the game you obtain experience by standing near your creeps while they fight the enemy ones. The distribution of heroes amongst lanes is generally designed to maximise the experience/gold “important” team members get. I’ll explain the specifics of how to behave in lane in another article.

Heroes, and more about team composition.
Dota 2 heroes
I mentioned there are 101 heroes. Thankfully, they can be grouped in various ways.
Note! Heroes are partitioned into Dire and Radiant, but players are free to choose any heroes independent of their faction.

By attribute: there are three “attributes” in Dota 2, and each hero has a primary one, which gives a rough indication of how they’re played:

  • Strength: influences hit points and base health regen. ~”Tanks”. Usually melée.
  • Agility: influences attack speed and armour. ~”DPS”.
  • Intelligence: influences mana pool and mana regen. ~”Wizards”. Often ranged.

By function: this is more meaningful, but less immediately obvious at the selection screen. Very very roughly, the basic roles are:

  • Carry: purpose: becoming an unkillable machine of destruction. Carries are those “important” heroes which, if given enough gold and experience, become incredibly dangerous. They are defined by this property. CARRIES REQUIRE GOLD. CARRIES ARE SELFISH. If you’re a new player, you probably won’t be playing a carry. Carries are often agility heroes. Examples: Antimage, Faceless Void, Phantom Lancer, Ursa, Lifestealer, Shadow Fiend, Luna, Riki, Phantom Assassin, …
  • Support: purpose: selflessly helping the team. A support is basically the opposite of a carry. They’re a hero which does not benefit much from gold and experience, and is not expected to do much killing. A support buys useful items that benefit the team as a whole, and will often have skills that disable/stun/control enemies, enabling teammates to kill them. New players are often given support roles, because mistakes are more easily forgiven here. Supports are often intelligence heroes. Examples: Lich, Crystal Maiden, Dazzle, Witch Doctor, Tidehunter, Vengeful Spirit, …

After the support/carry distinction, roles are less prescriptive, but some additional ones are:

  • Ganker: purpose: swiftly murdering single enemies. A ganker might have very high burst damage, or skills enabling them to creep up on enemies (eg: invisibility, blink, other movement-based skills) or disable them. You should fear gankers. Examples: Queen of Pain, Spirit Breaker, Bounty Hunter, Nature’s Prophet, …
  • Initiator: purpose: starting team-fights. This means they have some skill which is particularly effective for this purpose. A proper initiation can greatly influence the outcome of a fight, so new players are unlikely to be given this role. Examples: Tidehunter, Earthshaker, Magnus, Enigma, …
  • Pusher: purpose: “pushing lanes”, that is to say, destroying enemy towers. Such heroes may have good area damage (for killing entire enemy creep waves at once), or have control of units which can “tank” towers while they attack them. A team which includes many pushing heroes is usually trying to end the game quickly. Examples: Venomancer, Broodmother, Leshrac, Phantom Lancer, …
  • Jungler: purpose: starts the game in the jungle, thus enabling other lanes to have fewer heroes and more experience! Only a few heroes “can” jungle successfully, and the play style is a bit different, so new players are unlikely to jungle. Examples: Ursa, Nature’s Prophet, Lifestealer, Enigma, Axe, …
  • Solo laner: this is a hero that can survive in a lane on their own, usually against 2+ enemies. Escape abilities are essential, and being ranged helps. In this position, getting experience/gold can be difficult, so this hero is unlikely to carry. Examples: Windrunner, Dark Seer, Bounty Hunter, Mirana, Nature’s Prophet, …Some of the examples I gave overlap, which reflects the fact that hero role is not entirely set in stone. However, if you pick a “classic support” hero such as Crystal Maiden and try to play them as a carry, your team will shout at you. There is a natural order in Dota 2, and respecting it yields results.Actually playing the game.
    So that is the basic premise of Dota 2: you choose a collection of heroes with skills such that you can defeat the enemy team, and subsequently destroy their home. Now, naturally, you want to play. The game interface is quite intuitive, but here are the basic components nonetheless:
    Dota 2 hud
    From left to right:
  • The minimap: Enemy heroes (if visible) will appear as coloured Xes. Allies are circles. Look at the minimap.
  • Hero portrait and level: check out the cleavage on this ghost. :| Not pictured: the level bar fills up.
  • Stats: We have attack damage (sword), armour (shield), move speed (boots). If you hover over this you’ll get more information, like attack speed and what your armour score actually means (% damage reduction). The green bar going across the top is your hitpoints, and blue is mana pool.
  • Attributes: Red is strength, green is agility, blue is intelligence. Vengeful Spirit is an agility hero, so her agility icon has a little gold circle around it.
  • Skills: As I said, most heroes have four skills. Here they are, with their key-binds (adjustable). The gold boxes underneath tell you what level that skill is. Every time you level up you can choose an ability to improve. Vengeful Spirit’s third skill is passive, so it is not selectable. The fourth skill is called the “ult”, because it is usually pretty impressive (and has a long cool-down). In the bottom corner of the skill icon, the mana cost is given. Hovering over any skill gives a description of it, and shows its cast range if applicable.
    Magic missile on venge
  • Items: You have space for six items. Some items can be “used”, so they have key-binds. You can see which ones I use. The items I’ve included are very important. The top three are all regeneration items (health, mana) and the three on the bottom are: boots (to increase your movement speed), wards (these can be placed on the ground and give vision for 6 minutes), teleport scroll (you can use this to teleport to any friendly building, useful for escaping back to base).
  • Gold and shop: You can see your gold (note! Vengeful spirit will never have this much gold.) and the button to open the shop tab.


The shop is slightly confusing at first, but there is a search function which will enable you to find items by name. The left panel shows “suggested items”, which is a good place to start. You can also see what items are required to build a more complicated item.

Dota 2 shop

Many items can be purchased without being adjacent to a shop, but to acquire them you must physically go to the fountain (this is the place you spawn), or use a courier to bring them to you.
Less elementary Dota 2.
This is only the beginning. I haven’t mentioned many important and more advanced aspects of playing Dota 2, such as

  • Last hits and denying.
  • Creep equilibrium, stacking and pulling.
  • Wards and runes.
  • Roshan.
  • Ability and item effects, orb effects.
  • Game modes.
  • Skill/item builds.
  • Ridiculous tactics.
  • In the mean time, here are some links:
    Dota 2 Wiki: read about all the heroes, and the items, and the everything!
    Play Dota: this is the official website for Dota 1. Dota 2 is basically just a reskin of Dota 1, so while things will look a little bit different on this website, the information is relevant. This page contains useful skill builds for heroes.
    Frustration Free Beginner’s Guide to Dota 2: may be helpful. Yes, I did steal their idea of including pictures of the ancients. What are you going to do about it?Final advice.
    Dota 2 can be an incredibly frustrating but also deeply satisfying game. Because it is team-based, I strongly recommend playing it with friends. Communication is essential and the game can be very fast-paced, so using Mumble/Teamspeak/etc. really makes a difference. In addition, many players do not speak English, which can make coordinating strategies problematic. As well as making your team better, playing with friends can reduce the likelihood that you’ll encounter the unmitigated assholes who give the community a bad name.

Unless those people are your friends.

Sketch – Barbarian Warrior

I have recently started drawing again. Here is my first proper attempt in approximately four years.

This is pretty basic, drawn from reference: I didn’t focus much on realism when I was growing up, and I almost never drew male figures so this is an attempt to remedy that.

I can’t say how long it took because I was doing it on and off for a few hours.

Things I learned:

  • Feet are hard. Must not become Rob Liefeld and deal with this by avoidance.
  • I don’t know how to draw realistic-looking hair.
  • Everything in this drawing is approximately the same tone despite this not being the case in the reference. This makes the drawing somewhat flat. When I started the sketch the plan was to do it very quickly, however, so I didn’t want to spend ages carefully shading. It might have been better to roughly shade in the dark areas first, and then add detail before I got bored.

Problem 3.2 from Peskin and Schroeder

This question is actually shockingly easy. It’s one of those questions whose statement is so short and is literally just “prove this identity” that you assume it’s going to take pages of obtuse and demoralising mathematical trickery. Not this time!

The question demands that we prove the Gordon identity, and assures us that this identity will be used in Chapter 6. It goes as follows:

\bar{u}(p^{\prime})\gamma^{\mu}u(p)=\bar{u}(p^{\prime})\left[\frac{p^{\prime\mu}+p^{\mu}}{2m}+\frac{i \sigma^{\mu\nu}q_{\nu}}{2m}\right]u(p)

where q = p^\prime - p

I’m not going to explicitly go through the calculation of this because it’s trivial once you know the steps and have the necessary information about gamma matrices and whatnot.

  • Start by writing \gamma^{\mu}=\frac{1}{2}(\gamma^{\mu}+\gamma^{\mu}). This is a trick that dawned on me exactly half way through the solution (when I realised I was clearly missing a term) but the factor of a half in the RHS of the identity should give it away immediately, really.
  • What are u(p)? We can write down a plane wave solution to the Dirac equation as \psi(x) = u(p)\exp{(-i p \cdot x)} (we can do this since the field also satisfies the Klein-Gordon equation), so u(p) is a column vector with a constraint obtained from plugging this \psi into the Dirac equation[1],

(i\gamma^{\mu}\partial_{\mu}-m)\psi(x)=0 \rightarrow (\gamma^{\mu}p_{\mu} - m)u(p)=0

  • It’s not terribly important because it doesn’t actually impact the solution, but I feel it relevant to point out that what we have here is a four-dimensional matrix (not a scalar) acting on a column vector. Beside the m term is a sneaky invisible \mathbb{I}_{4}, since \gamma^{\mu} p_{\mu} is still a four-dimensional matrix, p_{\mu} being just a number (the \mu component of the momentum four-vector).
  • Use the above to write u(p) = \frac{\gamma^{\nu}p_{\nu}}{m} u(p) and substitute this in.
  • Recalling that \bar{u}(p') \equiv u^{\dagger}(p')\gamma^{0}, combine this with the above to write \bar{u}(p') = \bar{u}(p')\frac{\gamma^{\nu}p_{\nu}}{m}. (It is necessary to recall that (\gamma^{\nu})^{\dagger} = \gamma^0 \gamma^{\nu} \gamma^0 and (\gamma^{0})^2 = \mathbb{I}_4 to get here.)
  • After rewriting u(p) and \bar{u}(p') in this way, we end up having some terms like \gamma^{\mu}\gamma^{\nu}. This can be rewritten as g^{\mu\nu} - i \sigma^{\mu \nu} using (hint: adding together) the following properties of gamma matrices:

\{\gamma^{\mu},\gamma^{\nu}\} = 2 g^{\mu \nu}

[\gamma^{\mu},\gamma^{\nu}] = -2 i \sigma^{\mu \nu}

  • Noting that \sigma^{\mu \nu} is antisymmetric, we get… the result, as desired.
  • Just a note: remember that p_{\nu} is just a number and commutes with everything, so it can be neglected during gamma matrix manipulations.

I hope I have not just committed that wonderful crime students complain about,

“The result obviously follows…”

But… the result does follow, quite obviously!

1. I’m not going to attempt to use Feynman slash notation because I suspect that figuring out how to work it in WordPress will take longer than just writing “\gamma^{\mu}”. This will do, for now.

Problem 2.1 from Peskin and Schroeder

Chapter one being introductory, this is the first numbered problem in the book. There are of course plenty of potentially problematic points prior to the pressing problem, which I might get back to later, given sufficient time, but for now, let’s do some relaxing classical electrodynamics.

Without sources, we have the action

S = \int \mbox{d}^4 x \left( -\frac{1}{4} F_{\mu \nu} F^{\mu \nu} \right) where F_{\mu \nu} = \partial_{\mu} A_{\nu} - \partial_{\nu} A_{\mu}

(a) They want us to derive Maxwell’s equations as the Euler-Lagrange equations of this action, where we take A_{\mu} as the dynamical variables, then write them in standard form – that is, in terms of the electric and magnetic fields, using E^i = -F^{0i} and \epsilon^{i j k}B^k = -F^{ij}. Here, as is the convention, Greek letters such as \mu run over space and time (so 0,1,2,3) while Roman letters only run over space (1,2,3).

So, the Euler-Lagrange equations are

\partial_{\mu} \left( \frac{\partial \mathcal{L} }{ \partial (\partial_{\mu} A_{\nu})}\right) -\frac{\partial \mathcal{L}}{\partial A_{\nu}} = 0^{\nu}

Where \mathcal{L} is of course our Lagrangian (density, but let’s just call it Lagrangian because we’re doing field theory), the term in the brackets in the action.

We can immediately see that the second term vanishes, since F_{\mu \nu} only contains derivatives of A. If there was a source involved, we’d have some term like A_{\rho} J^{\rho} in the Lagrangian, where J^{\rho} is a four-current, and the second term would be non-zero, or have a chance of being non-zero, at least.

So we just care about calculating the first term. This question is actually very straightforward once you can do these sort of calculations, so I will go through it explicitly. Focusing on the bit in brackets in the first term, using the product rule,

\frac{\partial \mathcal{L}}{\partial (\partial_{\mu} A_{\nu})} = -\frac{1}{4} \frac{\partial (F_{\alpha \beta}F^{\alpha \beta})}{\partial (\partial_{\mu} A_{\nu})} = -\frac{1}{4}\left( F_{\alpha \beta} \frac{\partial F^{\alpha \beta}} { \partial(\partial_{\mu} A_{\nu})} + F^{\alpha \beta} \frac{\partial F_{\alpha \beta}} { \partial(\partial_{\mu} A_{\nu})} \right)

An important point – basically the entire problem – is to mind index grammar. That is to say, in \frac{\partial \mathcal{L} }{ \partial (\partial_{\mu} A_{\nu})}, the term we’re presently looking at, we have free indices \mu and \nu. To avoid ambiguity while including the scalar Lagrangian, we must choose the dummy indices different to the free ones. I have chosen \alpha and \beta because they’re at the start of the alphabet and are certainly not \mu or \nu, but you can pick anything you like. Thus we know we have summation over \alpha and \beta, since they are repeated. Did I mention the boring detail with which I would go through this?

Now we can write F_{\alpha \beta} \frac{\partial F^{\alpha \beta} } { \partial ( \partial_{\mu} A_{\nu} ) } as F^{\alpha \beta} \frac{\partial F_{\alpha \beta} } { \partial ( \partial_{\mu} A_{\nu} ) } by raising and lowering the \alpha and \beta indices. You get this from x_{\gamma}x^{\gamma} = x^{\rho}g_{\rho \gamma} g^{\gamma \sigma}x_{\sigma} = x^{\rho} \delta_{\rho}^{\sigma} x_{\sigma} = x^{\rho}x_{\rho} = x^{\gamma} x_{\gamma} (since \rho is just a dummy index). I feel like this particular step wouldn’t be legal if the metric tensor g had any dependence on, in this case \partial_{\mu} A_{\nu}, because then we couldn’t just smoothly extract it from the derivative. I’m not sure why the metric tensor would, but at any rate, it definitely doesn’t here, because we’re in flat Minkowski space. Phew! Just a side note there. Now we have

\frac{\partial \mathcal{L}}{\partial (\partial_{\mu} A_{\nu})} = -\frac{1}{2}\left(F^{\alpha \beta} \frac{\partial F_{\alpha \beta}} { \partial(\partial_{\mu} A_{\nu})} \right)

We must have \frac{\partial (\partial_{\alpha} A_{\beta})}{\partial(\partial_{\mu} A_{\nu})} = \delta_{\alpha}^{\mu} \delta_{\beta}^{\nu} by inspection, so \frac{\partial F_{\alpha \beta}}{\partial(\partial_{\mu} A_{\nu})} = \delta_{\alpha}^{\mu} \delta_{\beta}^{\nu} - \delta_{\beta}^{\mu} \delta_{\alpha}^{\nu}, through the definition of F. Then

\frac{\partial \mathcal{L}}{\partial (\partial_{\mu} A_{\nu})} = -\frac{1}{2} F^{\alpha \beta} \left( \delta_{\alpha}^{\mu} \delta_{\beta}^{\nu} - \delta_{\beta}^{\mu} \delta_{\alpha}^{\nu}\right) = -\frac{1}{2} \left( F^{\mu \nu} - F^{\nu \mu}\right)

F is antisymmetric, so we have to be careful with index order (as we should always be, anyway), and can write -F^{\nu \mu} = F^{\mu \nu}. Then

\frac{\partial \mathcal{L}}{\partial (\partial_{\mu} A_{\nu})} =- F^{\mu \nu}=F^{\nu \mu}

So we now have everything we need for the Euler-Lagrange equations,

\partial_{\mu} \left( \frac{\partial \mathcal{L} }{ \partial (\partial_{\mu} A_{\nu})}\right) -\frac{\partial \mathcal{L}}{\partial A_{\nu}} = 0^{\nu}

\partial_{\mu} \left( \frac{\partial \mathcal{L} }{ \partial (\partial_{\mu} A_{\nu})}\right) - 0^{\nu} = 0^{\nu}

\partial_{\mu} F^{\mu \nu} = 0^{\nu}

Maxwell’s equations! Now let’s write them in a more familiar form. We can see that \nu is a free index, so let’s choose some values for it.

\nu = 0:

\partial_{\mu} F^{\mu 0} = \partial_{0} F^{00} + \partial_{i} F^{i 0} = 0 + \partial_{i} E^i=0 \rightarrow \nabla \cdot \mathbf{E} = 0

This is the sourceless form of Gauss’s law. Makes sense, right? In the absence of sources, the electric field has vanishing divergence. It’s entirely intuitive if your understanding of divergence is as something which vanishes in the absence of soruces, at any rate. Moving swiftly along,

\nu = i:

\partial_{\mu} F^{\mu i} = \partial_{0} F^{0i} + \partial_{j} F^{j i} = -\partial_{0} E^i - \partial_{j} F^{ij} = 0^i

\rightarrow \partial_{0} E^{i} + \partial_{j} F^{ij} = \dot{E}^{i} + \partial_{j} ( -\epsilon^{i j k} B^k ) = 0^i

The second term here is just the index form of the curl, \nabla \times \mathbf{B}, so we get the equation

\dot{\mathbf{E}} = \nabla \times \mathbf{B}, which is also known as Ampère’s circuital law.

At this point we are technically missing two of Maxwell’s equations. In the classical field theory course I took, we obtained the last two by noticing the vanishing divergence of the dual (the Hodge dual if I am not mistaken) of the field tensor F, being \tilde{F}^{\mu \nu} = \frac{1}{2} \epsilon^{\mu \nu \rho \sigma} F_{\rho \sigma} (where this is not the same \epsilon we were dealing with above – notice its four indices). I feel like they’e only asking for the first two in this question, however. Nonetheless, the rest are easily obtained by looking at different values for \nu in \partial_{\mu} \tilde{F}^{\mu \nu} = 0^{\nu} as we did above. Getting the electric and magnetic fields out is slightly more involved, but nothing too complicated.

(b) We are asked to construct the energy-momentum tensor for this theory, and then, essentially, to symmetrise it. Let’s start with the non-symmetric form, anyway. So, the definition of the energy-momentum tensor, knowing the Lagrangian and dynamical variables, is (this is in the book for a scalar field, anyway)

T^{\mu}_{\nu} \equiv \frac{\partial \mathcal{L}}{\partial(\partial_{\mu} A_{\alpha})}\partial_{\nu}A_{\alpha} - \mathcal{L} \delta^{\mu}_{\nu}

This is not an arbitrary formula that someone made up. This is the conserved Noether current arising from the symmetry of the theory under spacetime transformations. Invariance under time transformation (homogeneity of time) gives us the conserved quantity we call “energy”, and invariance under space transformation (homogeneity of space) gives conserved linear momentum. Incidentally, invariance under rotations of space (isotropy of space) gives us conservation of angular momentum. Isotropy of time doesn’t make any sense (we need more than 1 time dimension if we’re going to rotate in it) so we’re not getting any quantities there.

So we already know what the derivative of the Lagrangian is from earlier, so this gives us

T^{\mu}_{\nu} = F^{\alpha \mu}\partial_{\nu} A_{\alpha} - \mathcal{L} \delta^{\mu}_{\nu}

Raising the \nu index using g^{\lambda \nu} and then relabelling \lambda \rightarrow \nu to bring my notation in line with theirs, we get something which is not symmetric,

T^{\mu \nu} = F^{\alpha \mu} \partial^{\nu} A_{\alpha} - \mathcal{L} \delta^{\mu \nu}

The question then suggests that we can remedy this by adding to T^{\mu \nu} a term of the form \partial_{\alpha} K^{\alpha \mu \nu}, the K^{\alpha \mu \nu} being antisymmetric in its first two indices. This is fine because the divergence of such an object vanishes (since \partial_{\mu} \partial_{\alpha} = \partial_{\alpha} \partial_{\mu}, but K^{\alpha \mu \nu} = - K^{\mu \alpha \nu}, to labour the point), so the total stress-energy tensor is still conserved (has vanishing divergence).

The question goes on to tell us to use K^{\alpha \mu \nu} = F^{\mu \alpha} A^{\nu} to get a symmetric stress energy tensor. How nice of them. Let’s check if this new tensor is symmetric.

\hat{T}^{\mu \nu} \equiv T^{\mu \nu} + \partial_{\alpha} (F^{\mu \alpha} A^{\nu}) = F^{\alpha \mu} \partial^{\nu} A_{\alpha} - \mathcal{L} \delta^{\mu \nu} + \partial_{\alpha} (F^{\mu \alpha} A^{\nu})

The Lagrangian term is clearly symmetric, so we can ignore that. What of the other two terms?

Let’s just expand out the new term. \partial_{\alpha} (F^{\mu \alpha} A^{\nu}) = \partial_{\alpha}( F^{\mu \alpha}) A^{\nu} + F^{\mu \alpha} \partial_{\alpha} A^{\nu}. But Maxwell’s equations say that \partial_{\alpha} F^{\mu \alpha} = 0^{\mu}, so that term goes away. So we just need to check the symmetry of

F^{\alpha \mu} \partial^{\nu} A_{\alpha} + F^{\mu \alpha} \partial_{\alpha} A^{\nu} = F^{\alpha \mu} \partial^{\nu} A_{\alpha} - F^{\alpha \mu} \partial_{\alpha} A^{\nu} = F^{\alpha \mu}(\partial^{\nu} A_{\alpha} - \partial_{\alpha} A^{\nu})

That is, F^{\alpha \mu} F^{\nu}_{\;\;\alpha}. This is symmetric! If we swap the order of the indices in both terms (each swapping induces a sign change, since each individual term is antisymmetric) it becomes more apparent. F^{\mu \alpha} F^{\;\;\nu}_{\alpha} = F^{\mu}_{\;\;\alpha} F^{\alpha \nu } , through raising and lowering the \alpha indices (perfectly legal), so now if \mu \rightarrow \nu, we just exchange the locations of each individual term while raising and lowering \alpha. This is fine because F^{\nu \alpha} for example, is just a scalar field ultimately. But wait, I hear you exclaim (or not), aren’t we talking about a tensor here? This is an important point: yes, F is a tensor, and it’s usually referred to as F^{\mu \nu} to remind us that it’s a second rank tensor (field) in a four-dimensional space(time), but the F^{\mu \nu} terms we have been messing with all this time are actually its components, which are themselves simply scalar fields. So what I just described was legal. I assure you, officer.

Finally, the question demands that we obtain the standard formulae for the electromagnetic energy and momentum densities from this energy-momentum tensor. These are just components of the tensor. They call them densities because we’ve been dealing in densities all along (remember when I dropped the descriptor from Lagrangian? Like many things in phyiscs – notably quantities like the speed of light and Planck’s constant – they were secretly there the whole time), so don’t panic at that. It just means we’ll have to integrate over space to get our real quantities.

The energy is \hat{T}^{00} = \mathcal{H} = \mathcal{E} (look again at our first definition of the stress-energy tensor!)

\hat{T}^{00}=F^{0}_{\;\; \alpha}F^{\alpha 0} - \mathcal{L} \delta^{0 0} = F^{0}_{\;\; i} F^{i 0} - \mathcal{L} = -F^{0 i} F^{i 0} - \mathcal{L} = \mathbf{E}^2 - \mathcal{L}

Now, what is \mathcal{L} in terms of the fields? \mathcal{L} = -\frac{1}{4}F^{\mu \nu}F_{\mu \nu}. Let’s forget about the coefficient and expand these F terms. First expand by \mu and then by \nu

F^{\mu \nu}F_{\mu \nu} = F^{0 \nu}F_{0 \nu} + F^{i \nu}F_{i \nu} = F^{0 i}F_{0 i} + F^{i 0}F_{i 0} + F^{i j}F_{i j}

Plugging the fields in then, we have

F^{\mu \nu}F_{\mu \nu}=2\mathbf{E}^2 +\epsilon^{i j k}B^k\epsilon_{i j l} B_{l}=2\mathbf{E}^2-\epsilon^{i j k}\epsilon_{i j l}B^{k} B^{l}

=2 \mathbf{E}^2- 2 \delta^{k l}B^{k}B^{l}=2 (\mathbf{E}^2-\mathbf{B}^2)

Using a property of Levi-Civita symbols at the end there.

Therefore, \hat{T}^{00}= \frac{1}{2} (\mathbf{E}^2 +\mathbf{B}^2) = \mathcal{E}

Now, for the momentum density. In this case \mu = 0 and \nu = i.

\hat{T}^{o i}=\mathcal{S}^i=F^{0}_{\;\;\alpha}F^{\alpha i }-\mathcal{L} \delta^{0 i}=F^{0}_{\;\;\alpha} F^{\alpha i} = F^{0}_{\;\; j} F^{j i} = F^{0 j} F^{i j}

\mathcal{S}^i= F^{0 j} F^{i j} = -E^{j} (- \epsilon^{i j k} B^k) = \epsilon^{i j k}E^{j}B^{k} = (\mathbf{E} \times \mathbf{B})^i

Which is, up to a constant of proportionality, the Poynting vector.

And now we are done. It’s not a difficult problem, but you do need to keep an eye on the indices.