Just For Fun

李亚普诺夫斯基的混乱天堂

Inkscape with textext on Windows, problem with texlive

leave a comment »

Inkscape + textext is a very cool tool for scientific graphics. It works well on my windows xp machine with Miktex2.7. But recently I got some weird problems after switching to texlive2010 (I didn’t uninstall Miktex, but just put texlive2010 before Miktex in the PATH environment.) I fixed this problem by changing the line:
paths += glob.glob(os.path.join(program_files, 'miktex*/miktex/bin'))
to
paths = paths + glob.glob(os.path.join(program_files, 'miktex*/miktex/bin'))
in the file “textext.py” .

It seems that textext works better with miktex, so I put miktex in front of texlive in the PATH.

Written by Jerry

November 23, 2010 at 1:23 pm

Posted in Uncategorized

These guys shapes the modern matrix theory

leave a comment »

I copied this post from Dan Simon’s book “Optimal State Estimation”, section 1.1.4. It’s interesting to see that most of the main framework of matrix theory was built in relative recent time.

In spite of this very early beginning (the use of matrices by Babylonians and ancient Chinese) it was not until the end of 17th century that serious investigation of matrix algebra began. In 1683, the Japanese mathematician Takakazu Seki Kowa wrote a book called “Method of Solving the Dissimulated Problems”. This book gives general methods for calculating determinants and presents examples for matrices as large as 5×5. Coincidentally, in the same year (1683) Gottfried Leibniz in Europe also first used determinants to solve systems of linear equations. Leibniz also discovered that a determinant could be expanded using any of the matrix columns.

In the middle of the 1700s, Colin Maclaurin and Gabriel Cramer published some major contributions to matrix theory. After that point, work on matrices became rather regular, with significant contributions by Etienne Bezout, Alexandre Vandermonde, Pierre Laplace, Joseph Lagrange, and Carl Gauss. The term “determinant” was first used in the modern sense by Augustin Cauchy in 1812 (although the word was used earlier by Gauss in a different sense). Cauchy also discovered matrix eigenvalues and diagonalization, and introduced the idea of similar matrices. He was the first to prove that every real symmetric matrix is diagonalizable.

James Sylvester (in 1850) was the first to use the term “matrix”. Sylvester moved to England in 1851 to became a lawyer and met Arthur Cayley, a fellow lawyer who was also interested in mathematics. Cayley saw the importance of the idea of matrices and in 1853 he invented matrix inversion. Cayley also proved that 2×2 and 3×3 matrices satisfy their own characteristic equations. The facet that a matrix satisfies its own characterization equation is now called Cayley-Hamilton theorem. The theorem has William Hamilton’s name associated with it because he proved the theorem for 4×4 matrices during the course of his work on quaternions.

Camille Jordan invented the Jordan canonical form of a matrix in 1870. Georg Frobenius proved in 1878 that all matrices satisfy their own characteristic equation (the Cayley Hamilton theorem). He also introduced the definition of the rank of a matrix. The nullity of a square matrix was defined by Sylvester in 1884. Karl Weierstrass’s and Leopold Kronecker’s publication in 1903 were instrumental in establishing matrix theory as an important branch of mathematics. Leon Mirsky’s book in 1955 helped solidify matrix theory as a fundamentally important topic in university mathematics.

Written by Jerry

October 20, 2010 at 1:44 pm

Posted in Uncategorized

Plan to modify Emacs org-mode

leave a comment »

Emacs org-mode is a nice tool for me to write notes. For me the most attractive feature is that I can write LaTex equations and export to html files.

However, the html file with equations look ugly, because the equation images are not properly aligned. I can’t tolerate a beautiful LaTex equation makes such an ugly webpage:
ugly_html

There is another light markup tool called jemdoc written in python, which also supports LaTex equations in html, but BEAUTIFULLY aligned. So I plan to study the codes for jemdoc, and immigrate the nice equation alignment to Emacs org-mode. I know a little bit python, and nothing on elisp, so I hope it won’t be too hard and take too much time.

Here is the idea in jemdoc:
1. Use a variable called “baseline”, whose value is the hight of equation $0123456789xxxXXxX$.
2. After generating each equation image, record the “height”.
3. offset = height – baseline + 1
4. In the generated html code for the equation image, set: style=”vertical-align: -height px”

If someone implement this idea before me, please let me know. I’ll be glad to try it.

Written by Jerry

June 10, 2010 at 3:58 pm

Posted in techniclick

Python under Win is really a pain!

leave a comment »

For English users, please ignore the next paragraph and jump to the process part directly.

想用python实现几个图论的小算法,发现了networkx和pygraphviz两个库,在archlinux下很容易地就用easy_install安装了这两个库,并且很顺利地运行了http://networkx.lanl.gov/gallery.html下面的一些测试程序。昨晚想在笔记本的xp上演示一下,于是找对应的windows版,本以为也可以用easy_install轻松装好,没想到问题一大堆,折腾的过程就不说了,就说一下怎么解决的吧,看了这个过程就知道在win下开发python有多麻烦了。

process: python2.6(enthought)+networkx(1.0 rc1)+pygraphviz(0.99.1) under windows xp sp3

When you proceed, please first try to install without my modification, because some bugs might have been fixed when you see this post.

1. Have python2.6 and mingw32 installed. I’m using enthought, which is the company that sponsors scipy. The academic version is FREE. For beginners like me, creating python tool chain from scratch (download python, scipy, numpy, matplotlib … separately) is really a frustrating process.

2. Install the “setuptools”(0.6c11.1) here http://pypi.python.org/pypi/setuptools#files, so that you can use easy_install. You can skip this step if you want to install networkx manually.

3. Install “networkx”(1.0rc1) using the command: “easy_install networkx”

4. Install “graphviz”(2.26.3) (yes, pygraphviz is just a python interface to graphviz, so you need to install graphviz first). You can’t install pygraphviz using easy_install, because it depends on graphviz, and the easy_install too can’t find the path of graphviz. So you need to download and install “graphviz” from here: http://www.graphviz.org/Download_windows.php

5. Install pygraphviz from source:

5.1 Download pygraphviz(0.99.1) from this link http://networkx.lanl.gov/pygraphviz/download.html, and extract it.

5.2 Modify “setup.py”

library_path='c:/Program Files/Graphviz2.26.3/lib/release/lib'
include_path='c:/Program Files/Graphviz2.26.3/include/graphviz'

5.3 Modify “c:\python26\lib\distutils\unixcompiler.py”, (for me it was line 282):

change
compiler = os.path.basename(sysconfig.get_config_var("CC"))
to
compiler = "gcc"

Otherwise there would be an error “TypeError: ‘NoneType’ object is unsubscriptable”, see this link “http://code.google.com/p/netcdf4-python/issues/detail?id=8”. I change it back after finishing installing pygraphviz for safety (I am a beginner).

5.4 Run command “python setup.py install” under the pygraphviz source directory. Now you should be able to install it.

6. Now the installation is done, but if you try to run the sample code such as edge_colormap, you might get an error: “close_fds is not supported on Windows platforms, balabala”. This was a bug of pygraphviz, I found it here and here. So I followed the links and modified line 1146 of site-packages/pygraphviz/agraph.py to

close_fds=False)

7. Now you should be able to run the test codes without error and begin to do your own work. Actually, my python crashes when I run the test codes “circular_tree” and “lanl_routes”. I don’t know why and really don’t want to spend time fixing it.

I hope those issues will be fixed soon so nobody have to follow this painful process. Working with python under windows is really a pain.

Written by Jerry

February 12, 2010 at 12:45 am

Posted in techniclick

加密

leave a comment »

今天跟Evg同学聊了一会儿会儿,学了一点关于pgp encryption,public key, private key的东西,花10分钟记下来。n年前考所谓的计算机3级网络技术时就把这些名词背得烂熟,却始终没搞明白到底是怎么回事,而Evg同学画个草图,5分钟就讲得明明白白,可见国内的考试认证是多么的没用。

1. public key(公钥) 和 private key(私钥)
A和B想在网络上安全的交流。A首先运行一个小程序,输入一个密码,小程序生成一对key,分别是公钥和私钥(也就是两串字符,比如公钥是Pubk_A,私钥是Prik_A,当然实际比这要长)。其中私钥是用A的密码加密过的,只有A知道;而公钥是A要公开给大家的,B,C,D都知道。

公钥和私钥有这样一个特点:如果你把信息用公钥加密,那只有这个对应的私钥能解开。

现在如果B要发消息”hello”给A,B先在自己的电脑上用A的公钥来加密这个消息,然后通过网络发给A。因为这个加密的消息只有通过A的私钥才能解密,所以即使是别人(比如C)在消息传播的途中截获了消息,他也没法解密,因为他只有A的公钥,而公钥是不能解密消息的。

2 签名
现在B已经可以放心地把消息发给A了,但A还不放心:他不知道消息是不是来自B的,因为所有人都有A的公钥。于是B除了要对消息(用A的公钥)加密之外,还需要加上签名,过程如下:

B首先对要发的消息进行Hash,得到一串字符,比如”hho”。Hash算法有这样一个特点,对一个输入能够得到一个确定的输出,但是你拿到这个输出,却没法算出它的输入(比如无论谁对”hello”进行Hash,都可以得到”hho”;但是我告诉你我把一串字符进行Hash得到”hho”,你永远不知道这串字符是什么)。然后B用自己的私钥(比如Prik_B)对Hash的结果”hho”进行加密,得到一个签名。这个签名可以用B的公钥(A,C,D都知道)来解密。

然后B把这个签名连同刚才用A的公钥加密的消息一起发给A。A首先用自己的私钥Prik_A把消息解密,得到”hello”;然后对消息进行Hash,得到”hho”;然后用B的公钥Pubk_B(所有人都知道B的公钥)对签名解密,发现也得到了”hho”,一致,于是断定消息确实是从B发来的。

上面的过程已经非常安全了: 首先,如果别人(比如C),在网络传输中截获了B发出来的消息和签名,他只能对签名进行解密,得到消息的Hash的结果”hho”,而因为Hash是不可逆的,所以他得不到消息。 第二,如果C想给A发一条消息”fuck you”,想办法让A以为是B发的,这也是不可能的,因为C他不知道B的私钥;A拿着B的公钥对签名解密,会发现得到的签名和A对消息解密后再Hash的结果不一致。

3 公钥的分配
可以看出来上面的过程非常安全了,大家只要记住自己的密码,就可以得到自己的私钥(没人愿意直接记住256位的私钥吧);然后告诉大家自己的公钥,然后就可以安全的交流了(虽然很麻烦)。但如果最开始告诉别人公钥的时候被人做了手脚怎么办呢?于是存在公钥的分配问题。

解决这个问题需要首先存在一个所有人都信任的分配公钥的机构Z(肯定不是中国政府或者cctv),这个机构告诉大家自己的公钥Pubk_z(所有人百分之百确定这个公钥就是Z的),大家也都告诉Z自己的公钥(Z负责确认这些公钥属于各自的主人)。然后Z用上面那一套方法把所有人的公钥分配给大家。

当然如果A在街上遇到B,可以直接把自己的公钥告诉B,而不去麻烦Z。

4 结语和鸣谢
感谢知识面广阔的Evg同学给我如此通俗易懂的解释。感谢发明Public-key cryptography, digital signatures这套系统以及RSA/DSA算法,Hash算法,PGP程序的前辈。

Written by Jerry

May 5, 2009 at 9:07 pm

Posted in techniclick

jemdoc和emacs org mode

leave a comment »

还是老毛病,有了整理一些笔记的想法,首先不是着手开始干,而是找个好工具。希望写出来的笔记能够发布成html发到网上。3个备选工具:wordpress自己对latex公式支持, jemdoc, 和emacs的org-mode。

第一个算是很方便,而且人家Terry Tao都在用这个写blog,但是似乎不够灵活,因为格式要求$\latex ...$ ,这样就只能在blog上用了。

第二个是Boyd的学生写的python程序,对latex的支持不错,并且对于生成image和文字的对齐做了调整,使公式和文字混合的比较自然,但不知道为什么不支持{align},并且生成的公式有些莫名其妙的问题需要我慢慢修改。并且我在windows下死也不能用公式,不知道是python的问题还是windows的问题。值得说的是jemdoc网上那个css文件太赞了,简单漂亮。

第三个顾名思义,是emacs下一个综合的笔记,日程管理的mode。方便的TODO列表,超级链接,输出各种格式,html,tex,pdf等。试了一下,很不错,如果我真的能够借助这个工具变成一个organized的人就好了。对公式和文字的对齐不太好,不知道我日后能不能参考jemdoc的代码来修改一下。奇怪的地方是不支持换行,在一个eqnarray环境里面,两行公式居然不能用回车分开,只能写成一行,不知道为什么。同样在windows下运行不成功。slackware工作在virtualbox的seamless mode实在是很爽。

回头看了一眼将近1年没有在这儿写东西了,发现自己又开始折腾了,惭愧,抓紧做正事。

Written by Jerry

March 30, 2009 at 9:53 pm

Posted in 1

成就感

leave a comment »

虽然很不想把我的blog变成我的自白书,但是每当想到自己身上的一些问题,总是不吐不快。这些问题不外乎围绕着学习方法和学习效果等等,都是我很早就应该很好的解决的了;毕竟现在已经是博士阶段,良好和高效的学习方法是最最起码的素质,本应该追求更高层次的研究上的创新与突破,考虑事业的选择和人脉培养,而我还在炒这些早就应该吃完的剩饭,心里觉得很惭愧,于是不自觉地就把blog写成了自白书。 Read the rest of this entry »

Written by Jerry

June 16, 2008 at 6:28 pm

Posted in struggle

Follow

Get every new post delivered to your Inbox.