Lecture 1
计算机所能做的最基本的两件事:
排除时间和空间因素,计算机也是有限制的,比如计算太复杂(如预测天气)或者基本不可能被计算出的问题(如图灵停机问题)
有关计算思维
Focus on concepts and tools of computational thinking.
Learn how to think like a computer scientist.
Skills:
computational thinking
understand code
understand ability & limits
map it into computation
有关于笔记
Not be handing out class notes. Students learn best when they take notes even if they never look at them. The process of writing is exercising both halves of your brain
区分开计算机和计算思维
Think like a computer scientist
-What is computation? Separate out which is computer from computational thinking.
知识分类
-What is knowledge?Two categories:
Declarative: √x is y means y²=x, x≥0 陈述性,有关事实
Imperative: 程序性,有关如何去做
start with guess G
if G²≈x stop -> G
otherwise new guess G <- (G + X/G) / 2
repeat
计算机发展
How do I build a mechanical process to capture that set of computation? A simple way is to build a little circuit to do this. That is actually an example of the earliest computers.
Fixed-program computers固定程序计算机
-calculator
-Atanasoff, 1941 -> solved linear equations线性方程
-Alan Turing bombe -> used during WWII to break German Enigma codes
推荐阅读《面对面的办公室——纪念艾伦•图灵百年诞辰》)
Suppose you could build a circuit with the following property属性: the input to this circuit would be any other circuit diagram. That circuit would wonderfully reconfigure itself to act like the circuits diagram.
It's going to change how it does the computation. That would be cool and that exists. It's called an interpreter. It is the basic heart of every computer. What it is doing, is saying, change the game. This is now an example of a stored-program computer.存储程序计算机
A traditional recipe actually is based on a small set of primitives, a good chef with that set of primitives, can create an unbounded number of great dishes. Same thing holds true in programming. Given a fixed set of primitives, a good programmer can program anything.
In 1936, Alan Turing showed that with six simple primitives, anything that could be described in a mechanical process. That's an incredible statement令人难以置信的声明. It says, with six primitives, I can rule the world. I can program anything.
A couple of really interesting consequences of that. One of them is anything you can do in one programming language, you can do in another programming language. There is nothing that you can do innn C that you can't do in Fortran. It's called Turing compatibility.图灵兼容,六个基本类型
python特性
没有更优秀的语言,实用性
Describe recipes -> need language
Python
-High vs. low level
-General vs. targetted
-Interpreted vs. compiled解释型与编译型
python是三个的前者
程序语言
Syntax - what are legal expression语法
"cat dog boy" (Lots of help. Python comes built-in with syntax checker, find one error each time)
Static semantics静态语义- what programs are meaningful, which expression make sense
语法上有效,且有意义
"My desk is Susan" (Some help.)
Full semantics完整语义 - what does program mean, what happen when run
语法正确,无静态语义错误,且只有一个意义(无二义性)。这一步出错的话机器是查不出来的,可能停止运行并报错,或陷入死循环,或输出一个错误结果。
两种基本元素
In Python, we have two primitive data elements to start with.
Numbers:
3 - integer
3.14 - floating point
Strings:
'abc'
And assiocate these simple things with operations: +,-,*,/
>>> 52
52
>>> 'abc'
'abc'
>>> 52*7
364
>>> print 52*7
364
>>> print '52*7'
52*7
>>> print '3'*'3'
TypeError
>>> print '3'*3
333
>>> print 52a
SyntaxError
>>> 3**5
243
>>> 3/5
0
>>> 3.0/5
0.5999999...
>>> print 'abc'+ 'de'
abcde
>>> myString = 'eric'
>>> myString
'eric'
两个字符串相乘会产生错误,但是一个字符串与数字相乘会被解释为将字符串重复几次。好的设计还是坏的设计?
参考摘要:
<http://blog.csdn.net/dc_726/article/details/7081413> <http://mooc.guokr.com/note/11212/>