Feb 29, 2012

Gauge fixing in classical electromagnetism

The Classical Solutions

Classical Electromagnetism Lagrangian:
\[ \mathcal{L} = - \frac{1}{4}F^{\mu \nu}F_{\mu\nu} + J_{\mu} A^{\mu}, \]where, $F^{\mu \nu} \triangleq \partial^\mu A^\nu - \partial^\nu A^\mu $. The metric is defined as: \[ g^{\mu \nu} = \begin{pmatrix} 1 & & & \\ & -1 & & \\ & & -1 & \\ & & & -1 \\ \end{pmatrix}. \] The theory has an nonphysical gauge symmetry (nonphysical degrees of freedom). But we can still get solutions in classical electromagnetism. The Equation of Motion reads, \[
( g_{\mu \nu} \partial^2 - \partial_\mu \partial_\nu ) A^\nu = - J_{\mu}. \qquad (1)
\] The free space solution can be obtained by Fourier Transform: \[
( k^2 g^{\mu \nu} - k^\mu k^\nu ) A_\nu = J^\mu.  \] It is convenient to introduce an operator $P^\mu_\nu \equiv \delta^\mu _\nu - \hat{k}^\mu \hat{k}_\nu $. It can be shown, $P\cdot P = P$. Therefore, $P$ is not invertible. We can seek for its pseudo-inverse. Notice that its eigenvalues satisfy $p^2 = p$. Hence $p = 0, 1$. Therefore $P$ is a pseudo-inverse of itself. The full solution can be obtained: \[
A^\mu = \frac{g^{\mu \nu} - \frac{k^\mu k^\nu}{k^2}}{k^2} J_\nu + \frac{k^\mu k^\nu} {k^2 } X_\nu
\] where $X_\nu$ is an arbitrary 4-vector. If we choose $X_\nu = \xi J_\nu /k^2$, $A^\mu$ becomes \[
A^\mu = \frac{g^{\mu \nu} - (1-\xi) \frac{k^\mu k^\nu}{k^2}}{k^2} J_\nu.
\] The resulted solutions are obviously less than the full solution. Equivalently, we have imposed a constraint on field $A^\mu$. This constraint is called a gauge. The gauge we choose here is called $R_\xi$ gauge, frequently used in Gauge Theory (Quantum Field Theory). $R_\xi$ gauge requires $k\cdot A= 0 $ or $\partial_\mu A^\mu = 0$. In fact, in classical electromagnetism, the current is conserved $\partial_\mu J^\mu = 0$ and the general solution is always \[ A^\mu = \frac{g^{\mu \nu}}{k^2} J_\nu + \frac{k^\mu k^\nu} {k^2 } X_\nu\]

The Lagrangian with Gauge Fixing

As we mentioned above, gauge fixing introduces a constraint to choose an explicit gauge: \[
\mathcal{G}[A] = 0 \]
Now we face a system with constraint(s). The normal procedure is to introduce a Lagrange multiplier term. \[
\mathcal{L} = - \frac{1}{4}F^{\mu \nu}F_{\mu\nu} + J_{\mu} A^{\mu} + \lambda \mathcal{G}[A].
\] In this post, we first investigate a co-variant gauge, the Lorenz gauge. By further assume the theory living in an d+1 Minkowski space (hence surfaces terms can be suppressed), the Lagrangian becomes, \[
\mathcal{L} = \frac{1}{2} A^\mu ( g_{\mu \nu} \partial^2 - \partial_\mu \partial_\nu ) A^\nu + J_{\mu} A^{\mu} + \frac{\lambda}{2} A^\mu \partial_\mu \partial_\nu A^\nu.
\] The last term, $ \frac{1}{2} \lambda(x) A^\mu \partial_\mu \partial_\nu A^\nu $ is a Lagrangian multiplier, that imposes gauge condition $( \partial_\nu A^\nu )^2 = 0 $.

Equation of Motion and Green's Function

The resulting Equation of Motion contains two equations:
$ ( g_{\mu \nu} \partial^2 + (\lambda - 1) \partial_\mu \partial_\nu ) A^\nu = - J_{\mu}. \qquad (1) $
$ ( \partial_\nu A^\nu )^2 = 0 \qquad (2) $
$(1), (2)$ imply $ \partial^2 A^\mu = - J^{\mu} $. The solution in free space is \[
A^\mu(x) = \int \mathrm{d}^4 x' J^\mu(x') \int \frac{\mathrm{d}^4 k}{(2\pi)^4} \frac{e^{i k \cdot (x-x')}}{k^2} = \int \mathrm{d}^3 \mathbf{x'} \frac{J^\mu(x'_\pm)}{|\mathbf{x-x'}|} \] where $x_\pm$ represents retarded and advanced coordinates: $x'_\pm = (t\mp |\mathbf{x-x'}|, \mathbf{x'})$.

Quantum Field Theory with Lagrange Multiplier

It's possible to start from a Lagrangian with Lagrange multiplier field to do QFT. Note that such a QFT converges to classical electromagnetism in classical limit. But whether or not it describes the true physics, is another issue.

[1]: Mark Srednicki, Quantum Field Theory.

Feb 17, 2012

on the algorithms of binomial coefficients

factorial based algorithms: 
The most naive definition of binomial coefficients is: \[ { n \choose m } = \frac{n!}{m! (n-m)!}, \] where $n!$ is factorial of $n$. However this formula is not a practical algorithm. The reason is the value of factorial increases extremely fast. For example if we want to calculate ${13 \choose 6 }$. Using above algorithm, $13! = 6227020800 > 2^{32} = 4294967296$ overflows the typical unsigned 4-byte integer. On the other hand, ${13 \choose 6 }= 1716$. In addition, the time complexity is $T(n, m) = O( n )$.

A more practical variation of this formula is: \[ { n \choose m } = \prod_{k=1}^m \frac{n-m+k}{k} = \frac{n}{m} \cdot \frac{n-1}{m-1} \cdots \frac{n-m+1}{1}. \] Also notice that $ { n \choose m } = { n \choose n - m }$. One can choose the smaller one to do computing: \[ { n \choose m } = \prod_{k=1}^{\bar{m}} \frac{n-\bar{m}+k}{k} \] where $\bar{m} = \min\{ m, n-m \}$. It can be shown the time complexity is only $T(n, m) = O( \bar{ m } )$.

recursive algorithms:
A recursive algorithm based on above algorithm is, \[ { n \choose m } = \frac{n}{m} \cdot { n - 1 \choose m - 1} \] with initial values $ {k \choose 0} = { 1 \choose l } = 1 \quad k, l \in \mathbb{N}, l \le 1$. $T(n,m) = O(\bar{m})$. Another recursive algorithm, known as Pascal's triangle (Meru-prastaara, Khayyam triangle, Yang Hui's triangle, Tartaglia's triangle) is, \[ {n \choose m} = { n - 1 \choose m - 1} + { n - 1 \choose m }\] with the same initial values above. $T(n,m) = O( n^2 )$.

falling factorial and gamma function based algorithm for generalized binomial coefficients:
Another thing one often encounters is the generalized binomial coefficients. For instance, the generalized binomial theorem states: \[ (x + y)^\alpha = \sum_{k=0}^\infty {\alpha \choose k} x^k y^{\alpha - k} \qquad ( x, y \in \mathbb{C}, | x | < | y |, \alpha \in \mathbb{R} ) \] where $ { \alpha \choose k } = \frac{\alpha \cdot (\alpha - 1) \cdots ( \alpha - k + 1)}{ k !} \equiv \frac{(\alpha)_k}{k!} $. Symbol $ (\cdot )_k$ is termed falling factorial. The algorithm for computing falling factorial fashioned binomial coefficients is the same as the one mentioned above.

The most general definition of binomial coefficients is via Gamma function or equivalent limit of some Gamma function: \[ { \alpha \choose \beta } \equiv \frac{\Gamma(\alpha + 1)}{\Gamma(\beta + 1) \Gamma(\alpha - \beta + 1)} \] with $\alpha, \beta \in \mathbb{C} $. There are several issues for using gamma function in practical computing. First of all, they are computationally complex. Therefore, only if $m$ in ${n \choose m}$ is not an integer (which is rare in practice), Gamma function definition could be used. In that case, one actually only need the initial values for $\Gamma(s) \quad (0 \le s \le 1)$. Calculation of gamma function can be obtained by Lanczos approximation:
\Gamma(z) = \sqrt{2 \pi} (z + g + \frac{1}{2})^{z + \frac{1}{2}}e^{- (z + g + \frac{1}{2})} A_g(z)
\] where, $g$ is an arbitrary constant subject to restriction $\text{Re}( z + g + \frac{1}{2}) > 0$. The reflection formula \[ \Gamma(z) \Gamma(1-z) = \frac{\pi}{\sin(\pi z)} \] can be used to achieve this. \[ A_g(z) = c_0 + \sum_{k=1}^\infty \frac{c_k}{z + k} \] where $c_k$ are pre-calculable constants. GNU Scientific Library choose $g = 7$, and the first 9 coefficients are given such that 15 correct digits are guaranteed:

$c_0 = 0.99999999999980993$,
$c_1 = 676.5203681218851$,
$c_2 = -1259.1392167224028$,
$c_3 = 771.32342877765313$,
$c_4 = -176.61502916214059$,
$c_5 = 12.507343278686905$,
$c_6 = -0.13857109526572012$,
$c_7 = 9.9843695780195716\text{E}-6$,
$c_8 = 1.5056327351493116\text{E}-7 $.

Stirling's approximation and Spouge's approximation may also be used to calculate gamma function numerically, under different circumstance.

The second issue of gamma function definition, also reviewed in Lanczos approximation, is singularities at negative integers. However, binomial coefficients do not suffer from singularities. M. J. Kronenburg  (arXiv:1105.3689v1 [math.CO], 2011) extended the definition of binomial coefficients to arbitrary integer coefficients,  adopted by Mathematica 8. Let $n, m$ be integers, \[
{ n \choose m } = \left\{ \begin{array}{l l l}
& \frac{n!}{m! (n-m)!}                      &\qquad  (n \ge 0, 0\le m \le n );                    \\
& (-1)^m { -n + m - 1 \choose m }    &\qquad  (n < 0, m \ge 0 );                             \\
& (-1)^{n-m} { -m-1 \choose n - m} &\qquad  (n < 0, m \le n  );                             \\
& 0                                                     &\qquad   \text{ others }.                                \\

logarithm method:
${ n \choose m }$ is bounded in, \[ \left(\frac{n}{k} \right) ^k \le { n \choose k } \le \left(\frac{n \text{e}}{k} \right)^k. \] This still may be a large number. In actuality, binomial coefficients emerging in intermediate processes may be very large, yet several binomial coefficients cancels out and result a relative small number at the end of the day. Thus it is inappropriate to evaluate binomial coefficients directly. The solution is to calculate \[ \log {n \choose m } = \sum_{k=1}^\bar{m} \log (n-\bar{m}+k) - \log(k) \] for each binomial coefficients, and add/subtract them depending on multiplication/division demand. At the end of the calculation, take exponential. Generalized binomial coefficients may not be positive. When using logarithm method, the absolute value and the sign should be considered separately.  

Feb 16, 2012

Ubuntu Linux 11.10 Setup Notes




  2. sudo apt-get install gnome-session-fallback
sudo apt-get install gnome-shell

2. add/remove gadget to the panels.
alt + right click

3. add/manage printers.


Several alternative GUI printer managers are available:
Cups printer manager:

  1. open a web browser.
  2. type in, and hit enter.
You can make a launcher for this in menu Applications:
right click Applications -> Edit Menus

 4. scrollbars in Eclipse.


  2. sudo vim /etc/X11/Xsession.d/80overlayscrollbars
  3. append the following text:
  4. restart Eclipse.
If you want to use overlay scrollbar in Eclipse:
  1. $sudo vim /usr/bin/eclipse
  2. comment the line:
  4. restart Eclipse.
5. nautilus crashes when accessing some folders.




6. system monitor

sudo apt-get install gnome-system-monitor 
sudo apt-get install indicator-multiload 
sudo apt-get install indicator-weather

there are two issues.

7. Screen Reader screws up synaptic




8. where is Sun-java6?


One can install sun-java6 from LFFL ppa:
sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
And about oracle-java7?  Forget about it!


9. Input Method (im) set up

system settings -> language support -> install/remove languages 

Configuring ibus:




sudo apt-get install ibus-gtk ibus-qt
2). In profiles
sudo vim /etc/profile
vim ~/.profile
add the following lines for ibus,
# ibus
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus

Configuring scim:




1). Add locale support to scim

To display locales:
locale | grep LANG=
add it ( for instance en_GB.UTF-8 ) to
vim ~/.scim/global
in line
/SupportedUnicodeLocales = en_US.UFT-8,en_GB.UTF-8
Use comma to separate more than one locales.

sudo apt-get install scim-bridge
sudo vim /etc/X11/xinit/xinput.d/scim

sudo vim /etc/profile
vim ~/.profile
add the following lines if use scim:

export XMODIFIERS='@im=SCIM'
export GTK_IM_MODULE="scim"
export XIM_PROGRAM="scim -d"
export QT_IM_MODULE="scim"
scim -d


trouble shooting:


10. Mathematica Crashes with SIGSEGV error:


change the line
Driver "fglrx"
Driver "vesa"


11. Installing New Fonts

sudo mkdir ttf-myfonts
sudo cp ~/theDirIStoreTheFonts/*.ttf ttf-myfonts
cd ttf-myfonts
sodu chown root *.ttf
sudo mkfontdir
Web browsers may need configuration to display certain characters.


12. Convert a batch of  jpg pictures to gif pictures
replace ￥ above with $.
creating gif animation from a batch of gif pictures:
 13. Clock Calibration


sudo service ntp restart
restart service

ntpq -pn
query time servers
13. Tweak Login/Lock Screen Background

gksu gedit /etc/lightdm/unity-greeter.conf 



14. ssh session timeout and frozen

in /etc/ssh/ssh_config, add
(in client system) ServerAliveInterval time_in_second
(or in server system) ClientAliveInterval time_in_second