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

I have been a fan of Ubuntu Linux ever since 9.10. In fact, I am still using it on my old laptop. But when I got a new machine early this year (2012), I had to go to Ubuntu 11.10, in order to get softwares. As you may know, Ubuntu 11.10 adopts Gnome 3 (unity 2D), which reminds me of Windows Vista. I spent lots time adjusting little tiny damn things in this desktop. I decide to take notes on it for reference.

1. First thing first: switch from lame unity 2D to less but still lame Gnome 3 classic.

In order to do this, you must not choose update when/after installing Ubuntu.

  1. ctrl + Alt + T, to open a terminal;
  2. sudo apt-get install gnome-session-fallback
  3. logout. Before login, click the gear icon and choose GNOME Classic. The reader may also try GNOME, GNOME Classic (No Effect), Ubuntu, Ubuntu 2D.
There are several alternatives at the 2nd step, that I haven't tried. They should work the same way.
sudo apt-get install gnome-shell
Ubuntu Software Center also offers a GUI installation of gnome-shell.

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

3. add/manage printers.

The default printer manager (system settings -> printers) is lame. It automatically detects your LAN printers, yet you'll find that you cannot distinguish them, for they are all called HP Laser Jet xxx.

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

  1. open a web browser.
  2. type in, and hit enter.
The classic GUI printer manager in Gnome 2.4 can be invoked by command:
You can make a launcher for this in menu Applications:
right click Applications -> Edit Menus

 4. scrollbars in Eclipse.

The overlay style scrollbars are incompatible with default settings of Eclipses. You'll only get partial overlay scrollbar, which makes it difficult to scroll. There are two solutions.

If you want to go back to classic gnome 2.4 scrollbar ( the scrollbar you see everyday ):
  1. ctrl + alt + T, to open a terminal;
  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.

This bug appears at least in Ubuntu 11.10. When opening or accessing some folders, nautilus crashes suddenly. The icons on desktop disappear. One cannot right-click on the desktop. When opening nautilus in a terminal, one get error information (see references).

It may be caused by a conflict between nautilus-open-terminal and ubuntuone-client-gnome. It is reported that removing either of them fixes the issue.

[1]: http://askubuntu.com/questions/65443/nautilus-on-ubuntu-11-10-keeps-crashing
[2]: http://askubuntu.com/questions/64244/nautilus-crashes-when-accessing-some-folders
[3]: https://bugs.launchpad.net/ubuntuone-client-gnome/stable-2-0/+bug/865567
[4]: https://bugs.launchpad.net/ubuntuone-client-gnome/stable-2-0/+bug/865115

6. system monitor

Today I installed xfce desktop, which is known as an iphoned desktop. xfce can be tuned thoroughly. It is more like the old gnome 2. Especially, old gnome fans can have their windows buttons back to the top left. Actually, it is customizable. I am satisfied with xfce, except for missing real-time system monitoring applet. The xfce-taskmanager sucks. The monitoring applets sucks too. The solution is to have gnome system monitor applet back.
sudo apt-get install gnome-system-monitor 
sudo apt-get install indicator-multiload 
sudo apt-get install indicator-weather
The second and third ones are the panel applet (cpu, memory, network traffic, weather etc) of gnome system monitor. One can use command line, launcher or simply put them into startup applicants, to use them. In xfce, they are put into notification area.

The calender applet also sucks. I find Orage 4.8.1. Orage provides various time formats via user  customized arguments.
there are two issues.
1. indicator-multiload and indicator-weather will also appear in Gnome Classic desktop, where I have two regular gnome system monitor and weather monitors.
2. For some reasons that I still don't figure out, every time I start xfce, nautilus is started and takes over the desktop. I believe it has something to do with the universal access.

7. Screen Reader screws up synaptic

My synaptic crashes today, with the following information if started in terminal:
09:43:27 yang@Weinberg:~$ sudo synapticterminate called after throwing an instance of 'std::out_of_range'what(): vector::_M_range_check
Synaptic is not used in ubuntu 11.10. So I suppose it has not been updated for new version of Gnome. This is a known bug caused by screen reader [1]. The solution is incredibly simple.
Go to System Settings -> Universal Access. Turn on and then turn off the screen reader toggle. [1, #16]
Let me copy the analysis made by the author of the solution post:
GNOME _used_ to have a global "enable accessibility" checkbox. It looks like that's been removed & is now handled automatically. If you're not using any individual accessibility option, the global setting is disabled for you. (For efficiency reasons).

But the old value of the global "enable accessibility" setting was preserved from before I upgraded.

The reason it only happens when GNOME is started normally, is because other environments don't set up accessibility.

8. where is Sun-java6?

Oracle bought SUN, as well as the awesome java. Since then policy has been changed. Now even Starbuck is sued for using "java" in its posters. In ubuntu, sun-java6 is not available any more.
Oracle (Sun) Java 6 is no longer available to be distributed by Ubuntu, because of license issues.

It is recommended that users either migrate to OpenJDK, or download and install the newest version of Oracle (Sun) Java 6 manually, or switch to Oracle Java 7. Older versions of Oracle (Sun) Java 6 that have been distributed in the past are vulnerable to security exploits, see this announcement for more information.
One can install sun-java6 from LFFL ppa:
sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin
And about oracle-java7?  Forget about it!

[1]: https://help.ubuntu.com/community/Java#Oracle_.28Sun.29_Java_6
[2]: http://www.webupd8.org/2011/10/things-to-tweak-after-installing-ubuntu.html

9. Input Method (im) set up

I need an input method to input Chinese and other special characters, in a US English desktop environment. There are several im modules available: scim (development terminated around 2005), ibus, fcitx etc. I installed all of them. To configure im, go to:
system settings -> language support -> install/remove languages 
install languages you need. After installation, several languages appear in  table of "language for menus and windows". The last entry in use is always English. Languages below it are shaded and ignored. If you don't want, say, Chinese menus or Windows, don't drag Chinese above "English" entry. Namely, only keep English (United States), and English entries in use.

Configuring ibus:

In Keyboard Input Method system, choose ibus. Restart X (or simply logout and login). If the im is not started up, add ibus-daemon to startup applications. Start ibus-setup, under input method tab, add input methods needed such as Chinese, Thai, Japanese, Greek etc..

After these setups, one should be able to input special characters. Logout and login once, to apply changes. if im works but the input panel ( used to display input character candidates ) does not show up, restart to apply changes. See im setups ( for example, [1] ) for more details.

Well, life sometimes is not that easy. Even after these steps, one still cannot use im, or can use im in some applications, cannot in others. The following steps work for some versions of Ubuntu and other Linux distributions [2]. Make sure the settings are consistency.

1). use ibus-gtk/ibus-qt for gtk and kde applications.
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:

In Keyboard Input Method system, choose scim. Restart X (or simply logout and login). If the im is not started up, add ibus-daemon to startup applications. Start scim-setup, under input method tab, add input methods needed such as Chinese, Thai, Japanese, Greek etc..

After these setups, one should be able to input special characters. Logout and login once, to apply changes. If im works but input panel does not appear, reboot to apply changes. See im setups ( for example, [1] ) for more details.

The following steps can be tried if im still does not work well.

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.

2). Use scim-bridge/ibus-gtk/ibus-qt for gtk and kde applications:
sudo apt-get install scim-bridge
or install them in synaptic package manager. One may also need ibus-gtk3 etc. Then,
sudo vim /etc/X11/xinit/xinput.d/scim

3). Use scim for gtk, qt and old X applications:
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

Finally, one can also use im-swich / im-config to swich/config im applications. Logout and login again to apply changes. ( may need to install them )

trouble shooting:
If the system tray icon and/or candidate panel does not show after you try whatever prescriptions plus a logout/login, please try reboot your machine. My observation is, no matter what changes have been done to ibus/scim, one has to reboot to apply them. I still don't know why.

[1]: http://www.pinyinjoe.com/linux/ubuntu-11-chinese-setup.htm
[2]: https://help.ubuntu.com/community/SCIM

10. Mathematica Crashes with SIGSEGV error:

My Mathematica crashed suddenly when I tried to rotate a 3D object. Running in terminal, Mathematica gives the following information:
Mathematica has received the signal: SIGSEGV and has exited. If possible, please report this problem to support@wolfram.com describing in as much detail as possible what you were doing when the problem occurred.
On POSIX-compliant platforms, SIGSEGV is the signal sent to a process when it makes an invalid memory reference, or segmentation fault [1].

The only post I found relevant to this issue is [2]. They suggested to install X.Org X server -- VESA display driver and use it instead of fglrx:
/etc/X11/xorg.conf (back it up first!)
change the line
Driver "fglrx"
Driver "vesa"
What I did is to install fglrx-amdcccle. And it seems the issue is fixed.

[1]: http://en.wikipedia.org/wiki/SIGSEGV
[2]: http://mathforum.org/kb/message.jspa?messageID=5891352&tstart=0

11. Installing New Fonts

Ubuntu stores the fonts at /usr/locale/share/fonts . Download ttf fonts you need, make a directory in the fold, and copy the new fonts into it. Then make fonts directory:
cd /usr/local/share/fonts/true-type
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.

Of course, one may also simpler double-click to open fonts in fonts viewer, and then click the install fonts button ...

12. Convert a batch of  jpg pictures to gif pictures
 for pic in *.jpg; do echo ¥pic && convert ¥pic ¥pic.gif; done 
replace ¥ above with $.
creating gif animation from a batch of gif pictures:
 gifsicle --delay=10 160_*.gif > 160.gif
 13. Clock Calibration

I have no idea why my Ubuntu 10.10 has this issue: the clock eventually gets slower for 4 minutes, though it's set to be synchronized with network servers.

It's not adequate to adjust the clock by oneself. After googling, I found the package ntp, is the one I need to install. A few useful commands:
sudo service ntp restart
restart service

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

The solution for login background is from here. LightDM is a lightweight display manager that has been made default in Ubuntu 11.10 Oneiric Ocelot, replacing GDM. If you want to change the LightDM login screen background, all you have to do is edit a file and enter the path to the new background:
1. Open a terminal or press ALT + F2 and enter:
gksu gedit /etc/lightdm/unity-greeter.conf 
2. Scroll down to the line that begins with "background" - it should look like this:
And replace it with the exact path to the wallpaper you want to use for the LightDM background.

An alternative way is to rename a picture to warty-final-ubuntu.png and replace the default one. The default picture looks like:

It is said, tweaking the lock screen background is not allowed in ubuntu 11.10, but will be implemented as early as 12.10. Yet I once ran into an issue. After I used a customized picture as wallpaper and switched back to black later on, my lockscreen background becomes the very customized picture. It cannot be changed by reboot. Eventually, I changed the login background by using the above trick (but instead of using a specific picture, I removed warty-final-ubuntu.png), and after reboot, the lockscreen background simply disapeared, too.

14. ssh session timeout and frozen

After some time being idle, the ssh session will go timeout and freeze. To break (or escape from) it, simply type in enter, ~, . one by another. To avoid timeout, an active interval can be set, such that after that time, ssh will send the server (or client, either one will work) a message to keep it alive.
in /etc/ssh/ssh_config, add
(in client system) ServerAliveInterval time_in_second
(or in server system) ClientAliveInterval time_in_second