Thursday, November 26, 2009

Public toilet capacity analysis

Often you will see a longer queue in front of a female public toilet than its male counterpart. Putting the toilets as server and the users as job, this is a typical FIFO (i.e. first-come-first-serve) server-scheduling problem. Provided that we cannot perform load-balancing (i.e. female users claim male toilet for their use) and we cannot preempt job (i.e. drive anyone out of the toilet during his/her use), the solution is to redesign the capacity of the servers to cope with the estimated job incoming rate.

The model looks like the following. Let's assume there are two urinal pots and two loos in the male toilet; 3 loos in the female one. To execute a urine/poop job, male need 1.5 minutes and 5 minutes respectively; female need 2.5 minutes and 5 minutes respectively. Finally, let's assume that the incoming rate of jobs are on average 4 urinal and 1 poop per time frame for both. This is summarized in the table below.

For male server, it is 5 minutes of execution in both the worst and the best case. For female server, the optimal scheduling yields 5 minutes of execution time (with probability 3x4!/5! = 60%), and the worst case could be 7.5 minutes (with probability 40%). Therefore, on average, the execution time for female is 6 minutes.

How the situation is improved if there is one more loo in the female toilet? The average execution time will be 5.5 minutes. The disparity will be total closed if there are 5 loos in the female toilet.

Further discussion. In reality, there are other causes for female to go to public rest room, for example, fixing makeup, changing sanitary, gossip, etc. They are not taken into consideration here. But those factors are definitely going to affect the capacity of the servers.






ServerMF
Resource2U + 2L 3L
Execution time(1.5M, 5M) (2.5M, 5M)
Incoming rate 4U + 1L 4U + 1L

Thursday, November 19, 2009

Chinese is Object-Oriented Language

There are a lot of articles comparing Chinese and English to some extent. From the computer language design point of view, we shall see that Chinese is an object-oriented high-level language; while English or the like is index-based language.

Let us first look at what is Object-Oriented language. In the computer science, any concrete or abstract thing can be viewed as Object. Objects have their attributes and methods. Take “dog” as an example, color, weight and so on are its attributes; while eating, coquetry, barking etc are its methods.

Similarly, a Chinese character or an English word can also be viewd as an object. Once again, take “狗" (dog) as an example, the pronunciation and spelling are attributes of the word, and its meaning in usage is its method.

The most important concepts of Object-Oriented languages are: encapsulation, inheritance, and polymorphism.

1. Encapsulation

In software engineering, encapsulation means concealing the functional details of an object from its interface. This provides not only certain levels of protection of the data structure, but also excellent foundation for modularity.

The two features of encapsulation are: separation of interface and implementation and the protection of the internal implementation. By the same token, we can define the following four criteria to examine whether a natural language ensures encapsulation.

1. Shape interface: whether all words have consistent shape.
2. Semantics interface: whether there is unique definition of certain words.
3. Pronunciation interface: whether the pronunciation of certain words is unique.
4. Spelling interface: whether the spelling changes according to the different scenario.

Chinese. 1) Chinese characters have squared shape. 2) Most Chinese characters have multiple meanings. 3) Most Chinese characters have only one pronunciation; only a few (more than one hundred) have two or more ways of pronunciation. 4) Chinese characters’ spelling is fixed, despite that there are simplified and traditional spelling.

English. 1) English words can be arbitrary in length. For example, “I” has only one letter; and "pneumonoultramicroscopicsilicovolcanoconiosis" has a total of 45 letters. 2) Most English words have multiple meanings. For example, “book” in noun means differently from it in verb. 3) Most English words have unique pronunciation. 4) Spelling of English words is not fixed. The letters are case-sensitive; nouns have plural form; verbs have tense changes. And the pronunciation will change as well.

To compare them, “do” can appear to be “do”, “did”, “doing”, “done” in English, while in Chinese there is only a need for some commonly used adverb.

Conclusion: Chinese is a better encapsulated language of encapsulation

2. Inheritance

In object-oriented programming, inheritance is a way to form new classes (instances of which are called objects) using classes that have already been defined. Inheritance is intended to help reuse existing code with little or no modification.

For human language, there may not be hierarchies that rise from the inheritance relationship. Still, there are obviously compounds of roots (or 部首) for words and compounds of words for phrase, which make reusing word components possible. We will find that by using inheritance, language is much simpler for learners.

Single inheritance: Chinese characters are mostly made of parts (部首). Some parts are for the semantics (意); some parts are for the pronunciation (音). Therefore, one can guess the meaning of certain words without knowing how to pronounce it, or visa versa. For example, 围、圆、园、圈. These four words all have been circled with “口”; this is for the semantics meaning that they are something to do with circles. The inner parts 韦、员、元、卷 tells how to pronounce them. On the other hand, English has Latin roots that can be used to make words. This can be viewed as an example of single inheritance.

Multiple inheritance: which means to inherit from more than one classes. Chinese language does this in making phrases. For example,
  飞机(plane) = 会飞行(flight)的机器(machine)
  工人(worker) = 在工厂(factory)工作的人(man)
  解放(liberate) = 解开(unlatch)后释放(release)
  计算机(computer) = 能计算(calculate)的机器(machine)

English has such inheritance in the compounded words, such as: football, handwriting, and breakwater. However, there are also very bad examples that no inheritance can be found. For example:
猪 pig 公猪 boar 母猪 sow 小猪 piglet 猪肉 pork
牛 cattle 公牛 bull 母牛 cow 小牛 calf 牛肉 beef
羊 sheep 公羊 ram 母羊 ewe 小羊 lamb 羊肉 mutton
One shall see that there are only seven Chinese characters involved in representing these words: 猪、牛、羊、公、母、小、肉 whilst 15 words for English.

The last example, the months:
  一月 January
  二月 February
  三月 March
  四月 April
  五月 May
  六月 June
  七月 July
  八月 August
  九月 September
  十月 October
  十一月 November
  十二月 December
In Chinese, they are just numbers plus “月” for month. In English, they are twelve irrelevant words.

Conclusion: Chinese language is perfectly inheritance language, (given that five thousand years of Chinese history).

3. Polymorphism

Polymorphism (poly = multiple, morph = shape) is the ability of one type, A, to appear as and be used like another type, B. It provides the runtime flexibility for the language. Actually, polymorphism is a consequence of inheritance. By properly inherited from one interface (a.k.a. abstract base class), values of different data types can be handled using a uniform interface.

To exam whether a human language has polymorphism, we shall see 1) whether there exist words representing interfaces; 2) whether a word in a single interface can have different semantics in its context.

Starting comparison with an example, “我要坐车去” (I will go there by car). In English, it is quite definite that the transportation is “car”. In Chinese, however, “车” is an abstract word; it can refer to汽车 (car), 出租车 (taxi), 公共汽车 (bus), 火车 (train), etc. To be competent in English, one would have to say “I will go there by vehicle” – which sounds odd. Words like “车” that serves as an interface are quite common in Chinese, partly because a lot of compounded words are inherited from some single character.

Another type of polymorphism in Chinese is Pinyin. There are four tones for Pinyin. The tones sometimes are decided within its context, so called “多音字” (multi-tones character). Even the tones are provided, the meaning of the words have to be determined within the context in some cases. For example, “lì hài” can be “厉害” (Formidable) or “利害” (gains and losses, advantages and disadvantages).

Actually in English, the use of the tense is considered anti-polymorphism because the objects (words) changed their interface when its properties are changing; potentially increase the number of objects.

From the above examples, it is quite obvious that polymorphism provides certain degrees of flexibility in communication at the cost of preciseness. This probably is a feature of “information hiding” that makes languages more literally colorful.

To conclude this article, Chinese is, if not the only one, an Object-Oriented Natural Language; and English is definitely not.

Saturday, November 14, 2009

Home-moving is so tiresome

Money to pay
  • Home loan
  • Lawyer and broker charge
  • Strata
  • Council fee
  • Insurance
  • Hiring a house-moving truck
  • House cleaning

Things to setup

  • Electricity
  • Gas
  • Telephony
  • Broadband
  • Blinds and curtains
  • Lock
  • Security alarm

Furniture to buy

  • Dining table set
  • TV table
  • Coffee table
  • Bed x 2
  • Bed side tables
  • Lounge
  • Matts
  • (Kitchen is set)
  • (Closet is provided)
  • (Laundry and toilet are set)

Electrical appliance

  • TV
  • HiFi
  • Fridge
  • Microwave oven
  • Fan
  • Aircondition
  • Vacuum machine
  • Washing machine
  • Lamps
  • (Dishwasher and Oven are provided)
  • (Drier is provided)

Miscellaneous

  • Decoration
  • Power adapters
  • Cleaning tools
  • Gadgets
  • ..... too many

Monday, November 9, 2009

How to know how bad a program is written?

The answer is: try to debug it!
Every programmer should know how to make it easier for debugging before coding.

Sunday, November 8, 2009

A home fiance example for real

Let's name our leading character He.

He bought a piece of land and built his own home. Despite the horrible Fenshui, it is 25Km distance to the downtown and no public transportation around. He moved in the new house 1 month after it is established -- which means he paid one more month of rent, simply because the fence hadn't been setup. During that one month, his home was broken in and some kitchen stuff were stolen. Anyway, he still owes about 220K home loan to the bank.

He had a new 1.6L car 2 years ago. He then bought a new 2L car this year for family use. (BTW, a family of two). The second car is financed. He is paying 7% interest rate -- compared to 5%+ home loan rate. (Bank is so happy)

Last month, he was considering to quit the current job. Fortunately, he found a new better-paid job, which locates 1-hour-drive away. Therefore, he decided to buy a second home, closer to the job site, for about 390K. This shall be totally financed by the bank, because he spends more than 60K p.a. which left him no saving at all.

Friday, November 6, 2009

Thursday, November 5, 2009

Linux News (Cited)

1019日至20日,《Linux内核开发峰会》在日本东京召开,其间谷歌高层人员Mike Waychison到会披露:实际上,谷歌使用Linux是很无奈的(by perforce),由于任务紧急的需要,不得已而为之。谷歌从Linux 2.4.18入手,建立了自己的核心代码树,30来个人维护。根据谷歌计算实践的需要,补充了2,000多个文件,加入492,000行源代码。经过一年半左右,重新跟上主流版本,即Linux 2.6.18......Linux 2.6.26,又打了1,208补丁和30万多行源代码。谷歌实际使用Linux内核的水平,远远落后国际主流社区,以至于对外交流都存在一定的困难(技术语言障碍)。

Linux内核开发的领头人,Linus Torvalds先生当时就在现场,问他,你们为何不把修改代码提交出来?是因为是商业机密?还是什么内部原因?谷歌的Waychison先生很坦诚地说,不是因为商业机密,而是因为代码编写得很丑陋(ugly),不好意思拿出来。Waychison先生表示,谷歌目前正在力图改变这种状态,跟上国际主流社区。

1021日至23日,日本第一届Linux学术年会在东京召开,Linus Torvalds和《Linux基金会》主席Jim Zemlin有一次公开对话,题为“The impact of Linux(37分钟),Zemlin说道,在过去一年里面,Linux内核增加了2,700,000行源代码,平均每天增加10,923行源代码,同时,每天删除5,547行源代码。由此可见,Linux内核开发速度之快。实际上,Linux 2.6.31内核的最新版本,其总代码量已经超过1千万行源代码。Ubuntu 9.10版本就是基于Linux的最新内核开发的。很显然的事实是,谷歌的Chrome OS要想超越Ubuntu是不容易办到的。与其说,谷歌推出自己的操作系统Chrome OS是来对付微软,不如说,谷歌的Chrome OS主要是为解决自己的内部需要

Convert tab-delimited section into a table in MS Word

Just a few clicks, you can convert a tab-delimited section into a table in MS Word:
1, Highlight the section of tab-delimited paragraph (words that separated by tabs)
2, Select menu Table -> Insert -> Table
Done

For example,
A501 MARKETING COMMUNICATIONS Communications NULL
A502 WAREHOUSE/DISTRIBUTION Communications NULL
A503 PHOTOGRAPHY Branding NULL
A504 CONFERENCE/ROADSHOW Branding NULL
A505 INTERNAL COMMUNICATIONS Branding NULL

Becomes

A501

MARKETING COMMUNICATIONS

Communications

NULL

A502

WAREHOUSE/DISTRIBUTION

Communications

NULL

A503

PHOTOGRAPHY

Branding

NULL

A504

CONFERENCE/ROADSHOW

Branding

NULL

A505

INTERNAL COMMUNICATIONS

Branding

NULL



Wednesday, November 4, 2009

SSMS Tool Pack

Handy tool for SQL Management Studio

http://www.ssmstoolspack.com/

互联网的青春期

如果把互联网比作人,那它到底几岁了?

其实互联网的成长历程与普通人的成长历程有很多相似之处。

最早的互联网,诞生于实验室,大部分为美国军方所用。很多基本的互联网核心技术和互联网协议在那个时候定型。这个可以视为互联网的胎儿期(1960~1973)——简单,不完整。

随着APPANET逐渐扩张,和电脑及网络硬件的发展,互联网开始起步。这个阶段(1974~1989)互联网处于幼年期——受制于外部(硬件)环境,需要很多照顾,但本身并没有太多功用。

接着TCP/IP协议逐渐全球化,个人电脑和操作系统普及,为互联网特制的应用程序(比如Email,Mozilla)开始应运而生。互联网进入了少年期——这个时候(1990~1999),互联网的影响范围相当的小,相对比较单纯。

当人们不再为了千年虫担心,互联网的软硬件发展都开始提速。互联网开始在更多未知的领域发挥魅力,比如网络游戏和网络商务。用户群爆发性增长。互联网开始有了自己的发展引擎(如,搜索,云计算)不再受制于PC和PC软件。互联网成为了很多人生活的一部分。——互联网的青春期,发展日新月异,想象力丰富,影响力日深,
但这个时候,许多有害的因素也开始进入了互联网,比如DoS,病毒,Social Engineering,不良信息。就好比青春期的叛逆和不受控制。

无法想象互联网的成年(更年期?)会是如何呢。

Tuesday, November 3, 2009

Melbourne Cup

2:30 pm, Anna calls all of us to go to the board room. Snacks and Champagne have been prepared. Overhead projector has been set to display Sports channel live broadcast.
2:45 pm, Horses are set, people are ready.
3:00 pm, Race 7 concludes. Someone is excited.

I have only been to the horse racing and bet in the jockey club once in Hong Kong, as a tourists' sightseeing with my parents. That was quite happy.
To my surprise, Aussie take this cup very seriously. People take leave for it. It is said that it is a tradition -- like the Mardi Gras.
But why both Australian Open, famous horse racing are in Melbourn?