Archive for December, 2006

Turbulent Winds

Posted in Misc 2 years ago

The winds around the Burnaby mountain area were so bad yesterday. First, I was kept awake until 3 by the constant howling. When I finally fell asleep, I was abruptly woken up at 6am when my feet froze up. The winds had taken a bunch of power lines down and my building and the entire locality around the Lougheed Town Center was out of power.

Civilization just comes to a halt with a blackout. I couldn’t shower (electric heater) or groom myself, couldn’t make breakfast or lunch (electric cookers) or even see myself (sun rises at 9am and sets at 4pm). All of the stores around my place were closed. Just think of the lost opportunities.

Stanley park is in a state of chaos. There are fallen trees everywhere with power lines below them. There’s no power yet, so the place is pitch dark. A dangerous place to be.

Apparently, even MSFT1 was shut down today due to winds in the Redmond area.


  1. check out their new spiffy homepage ()

My LaTeX template

Posted in Computing 2 years ago

After about four or five years, I’ve become quite proficient at writing reports and documents with LaTeX. I’ve recently been asked by a couple of friends to send them a sample document which could be used as a reference.

The basics

You’ll be writing (or typesetting) plain text to a file. This file, usually with the extension .tex, is the source code or markup that’ll be compiled. On compilation, you’ll get a DeVice Independent (.dvi) file. This is an intermediate file format that can be converted into a variety of suitable formats by driver programs. You can have a PostScript driver, a PDF driver, a PNG driver or a driver for displaying the file on screen.

Programs

You’ll need the programs latex, dvips, gv, and pdflatex. These programs usually come in a package called tetex-base on Linux. You’ll also find it handy to use the DVI viewer xdvi. On windows, MikTeX provides the above tools. The DVI viewer is called yap (included with MikTeX.)

Our first document

LaTeX “markup” is a lot like XHTML. You can group a block of text with the \begin and \end tags (like div or a in XHTML):

\begin{document}
...
\end{document}

You can issue commands that do not need a closing tag (like img):

\newpage{}
\section{Introduction}

You can find numerous tutorials on the web about the syntax, so I won’t go into that. Our first complete document would be:

%% first.tex : Our first document
\documentclass{article}
\begin{document}
    Hello World
\end{document}

To get a PDF of the document, issue the following commands1:

latex first.tex
dvips first.dvi -o first.ps
ps2pdf first.ps first.pdf

It’s really that simple. The major drawback of this is that you need to key in these commands every time you want to view you document, which gets very tiring in a short while.

Samples

I never start a document from scratch. I’ve posted my template document that I’ve built over the years. Feel free to use and share it with your friends.


  1. you can also call pdflatex or dvipdf to skip intermediate steps ()

For a CEO

Posted in Business 2 years ago

I’m pretty exhausted from being up for almost 22 hours yesterday. Six of those were spent writing everything I had learnt in the last four months. They’re called exams.

A major chunk of the financial accounting exam was on justifying certain business decisions, or making suggestions to the CEO as his financial advisor. One of those questions I found really interesting:

You are the CEO of a mid-sized company. It’s typical to tie senior manager’s compensation with the performance of their respective divisions. Would you base the compensation based on the cash flow from operations, or on the net income? Give the pros and cons of each method.

Dynamic Programming

Posted in Computing 2 years ago

Let’s say you have an optimization problem that makes use of a cost function that needs to be computed over a set of discrete variables. For the sake of argument, assume that there is some sort of sub-structure or symmetry. How would you speed up the computation?

The simplest approach would be to build some sort of table for values that have been computed already. Then, instead of reevaluating the function each time, you can simply do a O(1) lookup.

The element of surprise here (atleast for me) is that this is called Dynamic Programming. I’m sure a lot of you have been using tricks like these for ages, but didn’t know what it was called. This new found knowledge has given me two things: keywords to search and preventing the NIH syndrome.

Consider a program to generate the Fibonacci sequence:

(defun fib(x)
  (cond ((= x 0) '0)
        ((= x 1) '1)
        (t (+ (fib (- x 1)) (fib (- x 2)))))
)

The simple code snippet seems to work really well, but it has two problems. The first problem obviously is the exponential growth in the return values of the algorithm. Using the standard integer data type will overflow at about 441. Secondly, the recursive nature of the algorithm necessitates computation of the same substructure over and over. This is evident in the following backtrace from emacs, calling fib with 6:

(0 1 2 1 0 1 2 3 4 1 0 1 2 3 0 1 2 1 0 1 2 3 4 5 6)

A lookup table, known as memoizing, will not solve the first problem, but will improve computation time considerably. This is pretty exciting stuff! Quickly skimming through some papers online led me to dynamic programming approaches in bioinformatics, control and information theory, signal processing (Viterbi algorithm), and ofcourse operations research.


  1. This is not a problem in lisp, which will autoconvert to BinInt. ()

Zero over Zero

Posted in Misc 2 years, 1 month ago

Zero over Zero

Dr James Anderson, a researcher from the University of Reading’s computer science department recently came up with a new way to represent the result of dividing zero with zero. I’ve long relied on signaling Not-a-Number (NaNS) to look for unstable or ill-conditioned numerical problems. I don’t see how this changes things the way they are right now.

Computers simply cannot divide by zero. Try it on your calculator and you’ll get an error message.

But Dr Anderson has come up with a theory that proposes a new number - ‘nullity’ - which sits outside the conventional number line (stretching from negative infinity, through zero, to positive infinity).

I’m passing along two counter-arguments that point out succinctly what’s wrong with the approach. Well worth a read: