House Prices Down Under

A look at historical house prices in Sydney and Melbourne from 1880 to 2010.

Historical house prices in Sydney and Melbourne from 1880 to 2010

Melbourne Median vs Average Wage 1965 - 2010.

Melbourne Median vs Average Wage 1965 - 2010

It must be remembered that house prices are determined by the demand and supply of credit, not the demand for and supply of housing.

房价不与国民收入,社会福利放在一起进行讨论,无异于光天化日里耍流氓。

AlphaGo movie

AlphaGo is an intriguing movie, full of striking imagery.

Proud of witnessing DeepMind and Google are making history …

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

AlphaGo movie

RESTful calls to create Index and Mappings in ElasticSearch

There is a simple way, using RESTful client to create Index and Mappings in ElasticSearch, for example, with ElasticSearch Head plugin.

Create Index in ElasticSearch with Settings JSON file. URL: http://localhost:9200/orders/, Method: PUT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter": {
"partial_matching_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 40
}
},
"normalizer": {
"lowercase_normalizer": {
"type": "custom",
"filter": ["lowercase"]
}
},
"analyzer": {
"partial_matcher": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"partial_matching_filter"
]
}
}
}
}
}
}

Create Mappings in ElasticSearch with Mappings JSON file. URL: http://localhost:9200/orders/_mapping/order, Method: PUT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
"dynamic": "false",
"_all": { "enabled": false},
"properties": {
"customer_id": {
"type": "keyword"
},
"encryption_key_id": {
"type": "keyword",
"index": "false"
},
"metadata_tags": {
"type": "text",
"analyzer": "whitespace"
},
"category": {
"type": "keyword"
},
"order_creation_date": {
"type": "date",
"format": "date_optional_time"
},
"order_reference": {
"type": "text"
},
"order_id": {
"type": "keyword",
"normalizer": "lowercase_normalizer"
},
"to_name": {
"type": "text",
"analyzer": "partial_matcher",
"search_analyzer": "standard"
},
"to_suburb": {
"type": "text",
"analyzer": "whitespace"
},
"to_state": {
"type": "text",
"analyzer": "whitespace"
},
"to_postcode": {
"type": "text",
"analyzer": "whitespace"
},
"to_email": {
"type": "text",
"analyzer": "whitespace"
}
}
}

To add a new fields to ElasticSearch, while dynamic mapping is off:

1
2
3
{
"dynamic": "false"
}

Run with additional fields JSON file, with URL: http://localhost:9200/orders/_mapping/order, Method: PUT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
"properties": {
"from_name": {
"type": "text",
"analyzer": "partial_matcher",
"search_analyzer": "standard"
},
"from_business_name": {
"type": "text",
"analyzer": "partial_matcher",
"search_analyzer": "standard"
},
"from_suburb": {
"type": "text",
"analyzer": "whitespace"
},
"from_state": {
"type": "text",
"analyzer": "whitespace"
},
"from_postcode": {
"type": "text",
"analyzer": "whitespace"
},
"from_country": {
"type": "text",
"analyzer": "whitespace"
},
"from_email": {
"type": "text",
"analyzer": "whitespace"
},
"from_phone": {
"type": "text",
"analyzer": "whitespace"
}
}
}

An ElasticSearch query example, with URL: http://localhost:9200/orders/_search, Method: POST

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{
"query": {
"bool": {
"must": [
{"match": {"customer_id": "1234567890"} },
{"simple_query_string": {
"query": "unlabelled+unmanifested",
"fields": ["metadata_tags"]
} },
{
"bool": {
"should": [
{
"multi_match": {
"query": "TerrenceMiao",
"fields": [
"name", "business_name", "order_id", "shipment_id", "sender_references", "article_ids"
]
}
},
{"match": {"phone": "abracadbravvv5/vv70qBu+/ve+/ve6EuA7vv70g77+9Su+/ve+/vX5y77+95JuV"} },
{
"multi_match": {
"query": "gdgdggddvvv75/vv70qBu+/ve+/ve6EuA7vv70g77+9Su+/ve+/vX5y77+95JuV",
"fields": [
"suburb", "state", "country", "postcode", "email"
]
}
}
]
}
},
{"simple_query_string": {
"query": "DESPATCH",
"fields": ["movement_type"]
} }
]
}
},
"sort": [
{"order_creation_date": {"order": "desc", "unmapped_type": "date"} },
{"shipment_creation_date": {"order": "desc"} }
],
"from": "0","size": "1"
}

An example query with date/time type in a range:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"query": {
"range": {
"shipment_creation_date": {
"gte": "2018-04-19T15:30:00",
"lte": "now",
"time_zone": "+10:00"

}
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {}
}

AWS access key id and secret access key

There are some secret of AWS credentials, i.e., its Access Key ID and Secret Access Key, which let you connect AWS services withouth authentication.

In a quintessential project environment, you have dev, test, prod environment setup in AWS. Your local AWS_PROFILE is something like this so you can switch to different targeting end services while run your application on localhost:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
𝜆 cat ~/.aws/credentials
[default]
aws_access_key_id=dev-aws_access_key_id
aws_secret_access_key=dev-aws_secret_access_key

[dev]
aws_access_key_id=dev-aws_access_key_id
aws_secret_access_key=dev-aws_secret_access_key

[test]
aws_access_key_id=test-aws_access_key_id
aws_secret_access_key=test-aws_secret_access_key

[prod]
aws_access_key_id=prod-aws_access_key_id
aws_secret_access_key=prod-aws_secret_access_key

When test Jest client in Test environment, a AWS ElasticSearch client library, error thrown:

1
2
3
2018-02-27 15:18:19 INFO  org.paradise.search.routes.ElasticSearchRoute  - Body: io.searchbox.core.Index@4804b850[uri=orders/order/4SMK1UmbtqIAAAFhmYAFt9V7,method=PUT] message: searchIndexRoute - updating search index
2018-02-27 15:18:19 INFO org.apache.camel.processor.interceptor.Tracer - >>> (searchIndexRoute) org.paradise.search.routes.ElasticSearchRoute$$Lambda$137/819330075@119b837 --> org.paradise.search.routes.ElasticSearchRoute$$Lambda$138/2035788375@2acacdf <<< Pattern:InOnly, BodyType:io.searchbox.core.Index
2018-02-27 15:18:19 ERROR org.paradise.search.routes.ElasticSearchRoute - Error while updating search index. 403 Forbidden {"Message":"User: arn:aws:iam::123456789012:user/svcbamboo is not authorized to perform: es:ESHttpPut on resource: paradise-esv5-test-esd"} at 'orders/order/4SMK1UmbtqIAAAFhmYAFt9V7'

It turns out that WRONG Dev AWS_PROFILE applied in Test environment.

Replacing “aws_access_key_id” and “aws_secret_access_key” from the default profile with “aws_access_key_id” and “aws_secret_access_key” from test profile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
𝜆 cat ~/.aws/credentials
[default]
aws_access_key_id=test-aws_access_key_id
aws_secret_access_key=test-aws_secret_access_key

[dev]
aws_access_key_id=dev-aws_access_key_id
aws_secret_access_key=dev-aws_secret_access_key

[test]
aws_access_key_id=test-aws_access_key_id
aws_secret_access_key=test-aws_secret_access_key

[prod]
aws_access_key_id=prod-aws_access_key_id
aws_secret_access_key=prod-aws_secret_access_key

Rerun the test and in log:

1
2
3
2018-02-27 15:23:54 INFO  org.paradise.search.routes.ElasticSearchRoute  - Body: io.searchbox.core.Index@62b18125[uri=orders/order/RVwK1UIBXmoAAAFhdJkFo9WA,method=PUT] message: searchIndexRoute - updating search index
2018-02-27 15:23:54 INFO org.apache.camel.processor.interceptor.Tracer - >>> (searchIndexRoute) org.paradise.search.routes.ElasticSearchRoute$$Lambda$137/1716909005@a809a62 --> org.paradise.search.routes.ElasticSearchRoute$$Lambda$138/612681832@4b2713b1 <<< Pattern:InOnly, BodyType:io.searchbox.core.Index
2018-02-27 15:23:55 INFO org.paradise.search.routes.ElasticSearchRoute - Finished updating search index at 'orders/order/RVwK1UIBXmoAAAFhdJkFo9WA'.

AWS ElasticSearch and Kibana proxy setup

There are several ways to access Amazon AWS ElasticSearch and Kibana services, which are HTTP based, without inject into HTTP request headers with authentication key …

AWS ES Proxy

Install a proxy application - AWS ES/Kibana Proxy. Download it from https://www.npmjs.com/package/aws-es-kibana and install:

1
$ npm install -g aws-es-kibana

Run AWS ES/Kibana Proxy then connect to ElasticSearch and Kibana services on AWS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ cat ~/.aws/config
[default]
output = json
region = ap-southeast-2

[profile sandy-test]
output = json
region = ap-southeast-2

$ cat ~/.aws/credentials
[default]
aws_access_key_id=Academy
aws_secret_access_key=Dingly Ding

[ap-test]
aws_access_key_id=Abracadbra
aws_secret_access_key=Somewhere Over The Rainbow

$ AWS_PROFILE=ap-test aws-es-kibana search-paradise-esv5-test-01-esd-blah23dlaoed81nz890adle4.ap-southeast-2.es.amazonaws.com
__________ _________ _________________ ________ ______
___ |_ | / /_ ___/ ___ ____/_ ___/ ___ __ \________________ ______ ____ /
__ /| |_ | /| / /_____ \ __ __/ _____ \ __ /_/ /_ ___/ __ \_ |/_/_ / / /_ /
_ ___ |_ |/ |/ / ____/ / _ /___ ____/ / _ ____/_ / / /_/ /_> < _ /_/ / /_/
/_/ |_|___/|__/ /____/ /_____/ /____/ /_/ /_/ \____//_/|_| _\__, / (_)
/____/
AWS ES cluster available at http://127.0.0.1:9200
Kibana available at http://127.0.0.1:9200/_plugin/kibana/

With Fish Shell:

1
2
3
4
5
6
7
8
9
𝜆 env AWS_PROFILE=ap-test aws-es-kibana search-paradise-esv5-test-01-esd-blah23dlaoed81nz890adle4.ap-southeast-2.es.amazonaws.com
__________ _________ _________________ ________ ______
___ |_ | / /_ ___/ ___ ____/_ ___/ ___ __ \________________ ______ ____ /
__ /| |_ | /| / /_____ \ __ __/ _____ \ __ /_/ /_ ___/ __ \_ |/_/_ / / /_ /
_ ___ |_ |/ |/ / ____/ / _ /___ ____/ / _ ____/_ / / /_/ /_> < _ /_/ / /_/
/_/ |_|___/|__/ /____/ /_____/ /____/ /_/ /_/ \____//_/|_| _\__, / (_)
/____/
AWS ES cluster available at http://127.0.0.1:9200
Kibana available at http://127.0.0.1:9200/_plugin/kibana/

SSH Tunnel

Set up SSH Tunnel for AWS ElasticSearch https://search-paradise-esv5-test-01-esd-blah23dlaoed81nz890adle4.ap-southeast-2.es.amazonaws.com from 443 port to localhost 9200:

1
𝜆 ssh -L 9200:search-paradise-esv5-test-01-esd-blah23dlaoed81nz890adle4.ap-southeast-2.es.amazonaws.com:443 -l ec2-user aws-jump-box

Then access AWS ElasticSearch at: https://localhost:9200, AWS Kibana at: https://localhost:9200/_plugin/kibana

ElasticSearch Head

With plugin ElasticSearch Head, to query ElasticSearch, using URL and index “orders-search-box” e.g. https://localhost:9200/orders-search-test/, and context path “_search”

Good things come to those who could wait till the last

And good things come in two (好事成双)。

想当初买耳机时对市场做过的一番调研,对欧洲,日本大厂的产品也略知一二。当同事介绍 Bluedio (蓝弦),一家从没听说过的中国广州公司生产的耳机时,以为仅是一家 Made In China,价廉低质的山寨产品。但被告知 Bluedio 耳机在亚马逊销量排行第二后,着实地大吃一斤。

Si vous voyez un entrepreneur chinois sauter par la fenêtre, suivez-le, il y a srement de bonnes affaires à faire (If you see a Chinese entrepreneur jumping out the window, follow him, there is certainly of good bargains to be done).

亚马逊的用户多非呆瓜。当吃瓜群众争先恐后地 jumping out of window 时,you have to follow. There is certainly of good bargains to be done.

货比三家后在 Aliexpress 下了单。

Bludio Ai

Bludio Ai

Bludio Ai

Bludio Ai

Bludio Ai

Bluedio Ai 从澳洲本土发货。三天后收到。

我对运动耳机要求不高。轻便,舒适,锻炼时不要总分心它会掉下来。用过从 $5 的 cheapy 到高端 Apple EarPods,没一个令人满意。

经过一段时间的使用,已感觉 Ai 是我所求。跑步时戴上感觉不到存在。耳机,人与自然达成和谐,已融为一体了。

Bludio F2

Bludio F2

Bludio F2

Bludio F2

Bludio F2

Bludio F2

从国内经阿里特快(免费的),Bluedio F2 两周后也到了。”F” 代表 Faith (忠诚)。F2 在外观设计上也忠诚地拷贝了著名的 Bose QC-35。One on one 比较,F2 在重量上比 QC-35 上了一个级别。但全金属 frame,让强烈厌恶塑料感的用户体会到厂家的温暖。耳机各个方面做工优异,用料实足,多处细节表现出匠人用心。

试听了 a wild range 不同风格的音乐作品后,you could feel the rich bass, warmer tone, not overpowering highs, and very detailed clarity from F2. 音质与高端耳机足有一拼。

Active Noise Cancelation (ANC) 不如 QC-35. 外界的蜂鸣声在经过 noise cancelation 后统统淹没在一片白噪声中。

谈到音质,F2 还不是 Bluedio 的最强产品。Bluedio 有一款 Victory 系列的 headphones,with 12 drivers,相当于有十二个 speakers 的一对音箱 built-in 小小的 headphones 里,提供了 studio level 的音质享受。对高品质继续 following.

Bludio products

Final thought.

$52 for a 高性价比的 wireless wheadphone plus ANC like this, nothing could go wrong. 惊喜之余,你会觉得对这个耳机每一分钱的投资都是物超所值。

Top range products on same market now like Sennheiser PXC 550 (Best Audio Quality), Sony WH1000XM2 (Most Elegant Design) and Bose QC 35 II (People’s Choice), cost 10x what you pay for Bluedio。Bluedio 在有些方面与顶级产品还有距离,but spend $500 for one 有额外享受的 headphone 是否真有所值? Furthermore, think about if you wear them cross the road, and you are run over by car, that will seriously damage these expensive headphones.

长城永不倒,国货当自强。

OnePlus 5T - a smartphone full of all the right ideas

Bought one OnePlus 5T Lava Red (熔岩红) special edition from OnePlus China website - http://rush.oneplus.cn/ in December 2017, when this edition is first available and exclusively sale in mainland China, which Red Colour is very popular in China that means bringing you a good fortune.

Un-boxing

OnePlus 5T Un-boxing

OnePlus 5T Un-boxing

OnePlus 5T Un-boxing

OnePlus 5T Un-boxing

OnePlus 5T Un-boxing

Dual SIMs

Dual SIMs support. Having two mobile network carriers ALL in active mode.

Dual SIMs

Performance Test

by AnTuTu Benchmark

Performance Test by AnTuTu

Performance Test by AnTuTu

by Geekbench

Performance Test by Geekbench

by SpeedTest - ADSL2 connection

Performance Test by SpeedTest - ADSL2 connection

Shooting Test

Support Dual Cameras and Portrait mode

Shooting Test

OnePlus Family

OnePlus One,OnePlus 2,OnePlus 3,OnePlus 5

OnePlus One,OnePlus 2,OnePlus 3,OnePlus 5, along with OnePlus 5T,一部完全一加手机的编年史,更显用户对高质量,高性价比的一加产品的喜爱与忠诚。

What OnePlus stands for is a no-gimmicks smartphone manufacturer build around a community.

For a good example, OnePlus 5T, a phone is full of all the right ideas - hardware design, software responsiveness, and overall usability.

打动用户的好产品自己会热销,不在乎卖到哪里。一加所做的一切,不过是努力把该做的做得更好。

长城永不倒,国货当自强。

Never Settle.

First ever half marathon trial

Try the first ever half marathon today - Yarra Boulevard run.

New experience such routine, Yarra Boulevard from suburb Kew to Hawthorn, either by walking or cycling.

Terrible weather condition today, windy and hot. Have to stop several time to get water supplied in case of dehydrated.

After 17km, left leg calf muscles start cramping, force me to reduce the pace. After 19km, right leg calf muscles also start cramping, but I keep moving forward.

New new personal best of Performance Level - 55 after run. Meanwhile, remind me there is limits inside me, but I know I can finish it.

First ever half marathon trial

Quotes from Johnnie Walker commercial:

“When the sun came shining and I was strolling and the wheat fields waving and the dust clouds rolling. As the fog was lifting, a voice was chanting, this land was made for you and me.”

“As I was walking that ribbon of highway, I saw above me that endless sky way. I saw below me that golden valley, Esta tierra fue hecha para ti y para mí.”

“I’ve roamed and rambled and I’ve followed my footsteps to the sparkling sands over diamond deserts, and all around me a voice was sounding, this land was made for you and me.”

Keep running!

浅谈程序员的数学修养

可能有很多朋友在网上看过 Google 公司早几年的招聘广告,它的第一题如下了:

{first 10-digit prime found in consecutive digits e}.com

e 中出现的连续的第一个10个数字组成的质数。

据说当时这个试题在美国很多地铁的出站口都有大幅广告,只要正确解答了这道题,在浏览器的地址栏中输入这个答案,就可以进入下一轮的测试,整个测试过程如同一个数学迷宫,直到你成为 Google 的一员。

又如 Intel 某年的一道面试题目:

巴拿赫病故于 1945年8月31日。他的出生年份恰好是他在世时某年年龄的平方。
问:他是哪年出生的? 这道看似很简单的数学问题,你能不能能快地解答呢?

下面则是一道世界第一大软件公司微软的招聘测试题:

中间只隔一个数字的两个素数被称为素数对,比如 5 和 7,17 和 19,证明素数对之间的数字总能被 6 整除
(假设这两个素数都大于 6),现在证明没有由三个素数组成的素数对。

这样的试题还有很多很多,这些题目乍初看上去都是一些数学问题。但是世界上一些著名的公司都把它们用于招聘测试,可见它们对新员工数学基础的重视。数学试题与应用程序试题是许多大型软件公司面试中指向性最明显的一类试题,这些试题就是考察应聘者的数学能力与计算机能力。某咨询公司的一名高级顾问曾说: 微软是一家电脑软件公司,当然要求其员工有一定的计算机和数学能力,面试中自然就会考察这类能力。微软的面试题目就考察了应聘人员对基础知识的掌握程度、对基础知识的应用能力,甚至暗含了对计算机基本原理的考察。所以,这样的面试题目的确很“毒辣”,足以筛选到合适的人。

四川大学数学学院的曹广福教授曾说过: “一个大学生将来的作为与他的数学修养有很大的关系”。

大学计算机专业学生都有感触,计算机专业课程中最难的几门课程莫过于离散数学、编译原理、数据结构,当然像组合数学、密码学、计算机图形学等课程也令许多人学起来相当吃力,很多自认为数据库学得很好的学生在范式、函数依赖、传递依赖等数学性比较强的概念面前感到力不从心,这些都是因为数学基础或者说数学知识的缺乏所造成的。数学是计算机的基础,这也是为什么考计算机专业研究生数学都采用最难试题 (数学一) 的原因,当然这也能促使一些新的交叉学科如数学与应用软件、信息与计算科学专业等飞速发展。

许多天才程序员本身就是数学尖子,众所周知,Bill Gates 的数学成绩一直都很棒,他甚至曾经期望当一名数学教授,他的母校 — 湖滨中学的数学系主任弗雷福·赖特曾这样谈起过他的学生: “他能用一种最简单的方法来解决某个代数或计算机问题,他可以用数学的方法来找到一条处理问题的捷径,我教了这么多年的书,没见过像他这样天分的数学奇才。他甚至可以和我工作过多年的那些优秀数学家媲美。当然,比尔也各方面表现得都很优秀,不仅仅是数学,他的知识面非常广泛,数学仅是他众多特长之一。”

影响一代中国程序人的金山软件股份有限公司董事长求伯君当年高考数学成绩满分进一步说明了问题。很多数学基础很好的人,一旦熟悉了某种计算机语言,他可以很快地理解一些算法的精髓,使之能够运用自如,并可能写出时间与空间复杂度都有明显改善的算法。

程序设计当中解决的相当一部分问题都会涉及各种各样的科学计算,这需要程序员具有什么样的基础呢? 实际问题转换为程序,要经过一个对问题抽象的过程,建立起完善的数学模型,只有这样,我们才能建立一个设计良好的程序。从中我们不难看出数学在程序设计领域的重要性。算法与计算理论是计算机程序设计领域的灵魂所在,是发挥程序设计者严谨,敏锐思维的有效工具,任何的程序设计语言都试图将之发挥得淋漓尽致。程序员需要一定的数学修养,不但是编程本身的需要,同时也是培养逻辑思维以及严谨的编程作风的需要。数学可以锻炼我们的思维能力,可以帮助我们解决现实中的问题。可以帮助我们更高的学习哲学。为什么经常有人对一些科学计算程序一筹莫展,他可以读懂每一行代码,但是却无法预测程序的预测结果,甚至对程序的结构与功能也一知半解,给他一个稍微复杂点的数学公式,他可能就不知道怎么把它变成计算机程序。很多程序员还停留在做做简单的 MIS,设计一下 MDI,写写简单的 Class 或用 SQL 语句实现查询等基础的编程工作上,对于一些需要用到数学知识的编程工作就避而远之,当然实现一个累加程序或者一个税率的换算程序还是很容易的,因为它们并不需要什么高深的数学知识。

一名有过 10 多年开发经验的老程序员曾说过: “所有程序的本质就是逻辑。技术你已经较好地掌握了,但只有完成逻辑能力的提高,你才能成为一名职业程序员。打一个比方吧,你会十八般武艺,刀枪棍棒都很精通,但就是力气不够,所以永远都上不了战场,这个力气对程序员而言就是逻辑能力 (其本质是一个人的数学修养,注意,不是数学知识)。”

程序员的数学修养不是一朝一夕就可以培养的。数学修养与数学知识不一样,修养需要一个长期的过程,而知识的学习可能只是一段短暂的时间。下面是一些我个人对于程序员如何提高与培养自己的数学修养的基本看法。

首先,应该意识到数学修养的重要性。作为一个优秀的程序员,一定的数学修养是十分重要也是必要的。数学是自然科学的基础,计算机科学实际上是数学的一个分支。计算机理论其实是很多数学知识的融合,软件工程需要图论,密码学需要数论,软件测试需要组合数学,计算机程序的编制更需要很多的数学知识,如集合论、排队论、离散数学、统计学,当然还有微积分。计算机科学一个最大的特征是信息与知识更新速度很快,随着数学知识与计算机理论的进一步结合,数据挖掘、模式识别、神经网络等分支科学得到了迅速发展,控制论、模糊数学、耗散理论、分形科学都促进了计算机软件理论、信息管理技术的发展。严格的说,一个数学基础不扎实的程序不能算一个合格的程序员,很多介绍计算机算法的书籍本身也就是数学知识的应用与计算机实现手册。

其次,自身数学知识的积累,培养自己的空间思维能力和逻辑判断能力。数学是一门分支众多的学科,我们无法在短暂的一生中学会所有的数学知识,像泛函理论、混沌理论以及一些非线性数学问题不是三五几天就可以掌握的。数学修养的培养并不在与数学知识的多少,但要求程序员有良好的数学学习能力,能够很快地把一些数学知识和自己正在解决的问题联系起来,很多理学大师虽然不是数学出身,但是他们对数学有很强的理解能力和敏锐的观察力,于是一系列新的学科诞生了,如计算化学、计算生物学、生物信息学、化学信息学、计算物理学,计算材料学等等。数学是自然学科的基础,计算机技术作为理论与实践的结合,更需要把数学的一些精髓融入其中。从计算机的诞生来看它就是在数学的基础上产生的,最简单的 0、1 进制就是一个古老的数学问题。程序设计作为一项创造性很强的职业,它需要程序员有一定的数学修养,也具有一定的数学知识的积累,可以更好地把一些数学原理与思想应用于实际的编程工作中去。学无止境,不断的学习是提高修养的必经之路。

第三,多在实践中运用数学。有些高等学校开设了一门这样的课程 —《数学建模》。我在大学时期也曾学过,这是一门内容很丰富的课程。它把很多相关的学科与数学都联系在一起,通过很多数学模型来解决实际的生产生活问题,很多问题的解决需要计算机程序来实现。我在大学和研究生阶段都参加过数学建模竞赛,获得了不少的经验,同时也进一步提高了自己的数学修养。实际上,现在的程序设计从某些角度来看就是一个数学建模的过程,模型的好坏关系到系统的成败,现在数学建模的思想已经用于计算机的许多相关学科中,不单只是计算机程序设计与算法分析。应该知道,数学是一门需要在实践中展示其魅力的科学,而计算机程序也是为帮助解决实际问题而编制的,因此,应该尽量使它们结合起来,在这个方面,计算机密码学是我认为运用数学知识最深最广泛的,每一个好的加密算法后面都有一个数学理论的支持,如椭圆曲线、背包问题、素数理论等。作为一名优秀的程序员,应该在实际工作中根据需要灵活运用数学知识,培养一定的数学建模能力,善于归纳总结,慢慢使自己的数学知识更加全面,数学修养得到进一步提高。

第四,程序员培养制度与教学的改革。许多程序员培养体制存在很多缺陷,一开始就要求学员能够快速精通某种语言,以语言为中心,对算法的核心思想与相关的数学知识都一笔带过,讲得很少,这造成很多程序员成为背程序的机器,这样不利于程序员自身的快速成长,也不利于程序员解决新问题。我在长期的程序员培训与计算机教学工作采用了一些与传统方式不一致的方法,收到了一定的效果。很多初学程序的人往往写程序时有时候会有思维中断,或者对一些稍难的程序觉得无法下手,我采用了一些课前解决数学小问题的方法来激励大家的学习兴趣,这些小问题不单单是脑筋急转弯,其中不少是很有代表意义的数学思考题。通过数学问题来做编程的热身运动,让学员在数学试题中激发自己的思维能力,记得有位专家曾经说过,经常做做数学题目会使自己变聪明,很长时间不去接触数学问题会使自己思维迟钝。通过一些经典的数学问题来培养学员的思维的严谨性和跳跃性。很多人可能不以为然,其实有些看似简单的问题并不一定能够快速给出答案,大脑也是在不断的运用中变更加灵活的。不信吗? 大家有兴趣可以做做下面这道题目,看看能不能在1分钟之内想到答案,这只是一道小学数学课后习题。很多人认为自己的数学基础很好,但是据说这道题目 90% 以上的人不能在一个小时内给出正确答案。试试,如果你觉得我说的是错的。

证明: AB + AC > DB + DC (D 为三角形 ABC 的一个内点)

最后,多学多问,多看好书,看经典。我在这里向大家推荐两部可能大家已经很熟悉的经典的计算机算法教材,它们中间很多内容其实就是数学知识的介绍。

第一部是《算法导论》,英文名称: Introduction to Algorithms,作者: Thomas H. Cormen ,Charles E. Leiserson ,Ronald L. Rivest ,Clifford Stein。本书的主要作者来自麻省理工大学计算机,作者之一 Ronald L. Rivest 由于其在公开秘钥密码算法 RSA 上的贡献获得了图灵奖。这本书目前是算法的标准教材,美国许多名校的计算机系都使用它,国内有些院校也将本书作为算法课程的教材。另外许多专业人员也经常引用它。本书基本包含了所有的经典算法,程序全部由伪代码实现,这更增添了本书的通用性,使得利用各种程序设计语言进行程序开发的程序员都可以作为参考。语言方面通俗,很适合作为算法教材和自学算法之用。

另一部是很多人都应该知道的 Donald E. Knuth 所著《计算机程序设计艺术》,英文名称: The Art of Computer Programming。 Donald E. Knuth 人生最辉煌的时刻在斯坦福大学计算机系渡过,美国计算机协会图灵奖的获得者,是本领域内当之无愧的泰斗。有戏言称搞计算机程序设计的不认识 Knuth 就等于搞物理的不知道爱因斯坦,搞数学的不知道欧拉,搞化学的不知道道尔顿。被简称为 TAOCP 的这本巨著内容博大精深,几乎涵盖了计算机程序设计算法与理论最重要的内容。现在发行的只有三卷,分别为基础运算法则,半数值算法,以及排序和搜索 (在写本文之际,第四卷已经出来了,我也在第一时间抢购了一本)。本书结合大量数学知识,分析不同应用领域中的各种算法,研究算法的复杂性,即算法的时间、空间效率,探讨各种适用算法等,其理论和实践价值得到了全世界计算机工作者的公认。书中引入的许多术语、得到的许多结论都变成了计算机领域的标准术语和被广泛引用的结果。另外,作者对有关领域的科学发展史也有深入研究,因此本书介绍众多研究成果的同时,也对其历史渊源和发展过程做了很好的介绍,这种特色在全球科学著作中是不多见的。至于本书的价值我觉得 Bill Gates 先生的话足以说明问题: “如果你认为你是一名真正优秀的程序员读 Knuth 的《计算机程序设计艺术》,如果你能读懂整套书的话,请给我发一份你的简历”。作者数学方面的功底造就了本书严谨的风格,虽然本书不是用当今流行的程序设计语言描述的,但这丝毫不损伤它 “程序设计史诗” 的地位。道理很简单,它内涵的设计思想是永远不会过时的。除非英语实在有困难,否则建议读者选用英文版。我个人就是阅读的该书的英文版,虽然花了不少 money 和时间,但是收获颇丰,值得。

总之,要想成为一名有潜力有发展前途的程序员,或者想成为程序员中的佼佼者,你一定要培养良好的数学修养。切记: 对于一名能够灵活自如编写各种程序的人,

数学是程序的灵魂。

Reference