MIT6.00 1x Lecture 1 - Introduction to Computation 学习笔记

来源:互联网 发布:赛思软件 编辑:程序博客网 时间:2024/05/16 07:50

l MIT6.00 1x (麻省理工:计算机科学和Python编程导论)

Lecture 1 - Introduction to Computation (计算科学简介)

1.1 Basics of computation(计算科学基础)

Goal:(本课程的目标)

– Become skillful at making a computer do whatyou want it to do

  熟练的让电脑做你想让他做的事

– Learn computational modes of thinking

  学习计算机科学的思考方式

– Master the art of computational problem solving

  掌握计算机科学解决问题的艺术

What does a computer do? (一台电脑能做什么)

• Fundamentally a computer:(一个基本的计算机)

– Performs calculations (执行计算)

– Remembers the results (纪录结果)

• What calculations?(什么是计算)

– Built in primitives(内置原语)

– Creating our own methods of calculating(创建我们自己的计算方法)

Is that all it does?(这就是它能做的所有么)

A billion calculations per second(每秒十亿次计算,超快速度)

100s of gigabytes of storage(超大容量)

Are simple calculations enough?(简单的计算就足够了么)

• Searching the World Wide Web (上网)

• Playing chess(下棋)

• Good algorithm design also needed toaccomplish a task!(即使速度很快,储存空间容量很大,我们依然需要良好的程序设计)

so are there limits?(有限制么)

Despite its speed and storage, a computerdoes have limitations

不管他的速度的储存空间,电脑依然有局限性。

– Some problems still too complex 一些任务仍太复杂

• Accurate weather prediction at a local scale 在一个具体地点的准确天气预报

• Cracking encryption schemes  破译加密

– Some problems are fundamentallyimpossible to compute 一些问题从根本上无法计算

• Predicting whether a piece of code will always halt with an answerfor any input

 (图灵停机问题)用一段代码预测另一端代码咋任意输入的条件下是否会停机

1.2 types of knowledge知识的类型

Computational problem solving 计算机科学中的问题解决

What is computation? 计算机科学是什么?

– What is knowledge? 有什么样的知识

– Declarative knowledge 陈述性知识

• Statements of fact 事实的陈述

– Imperative knowledge 程序性知识

• “how to” methods or recipes "如何做"方法

Declarative knowledge 陈述性知识

• “The square root of a number x is anumber y such that y*y = x”

 数字X的平方根是数字y 可得y×y=x²

• Can you use this to find the square rootof a particular instance of x?

 你能用这句话解一个特定x的平方根么?

Imperative knowledge 程序性知识

• Here is a “recipe” for deducing a square rootof a number x – attributed to Heron of Alexandria in the first century AD

 这有一个方法推导数字x的平方根,亚历山大的海伦在公元一世纪提供

• Start with a guess, called g

 任取一个猜测的数,定义为g

• If g*g is close enough to x, stop and saythat g is the answer

 如果g*g足够接近x,结束并得出g是答案

• Otherwise make a new guess, by averagingg and x/g

 否则取g和x/g做一次新猜测

• Using this new guess, repeat the processuntil we get close enough

使用新猜测,重复步骤直到足够接近x

An example 一个例子

• Find the square root of 25 找到25的平方根

g

g*g

x/g

(g+x/g)/2

任取g=3

9与25不接近

8.33

5.67

5.67

32.11与25不接近

4.41

5.04

5.04

25.40与25接近,输出5.04

 

 

 

Algorithms are recipes 算法就像菜谱

做鸡蛋羹的菜谱:

1. Put custard mixture over heat 把鸡蛋羹加热

2. Stir 搅拌

3. Dip spoon in custard 用勺子蘸鸡蛋羹

4. Remove spoon and run finger across backof spoon 拿出来勺子然后用手摸勺子的背面

5. If clear path is left, remove custardfrom heat and let cool 如果勺子没粘上鸡蛋羹则把奶油放凉

6. Otherwise repeat from step 2 否则从步骤2开始重复

1.3 basic machine architecture 基本的机器架构

How do we capture a recipe in a mechanical process?

我们如何把算法转化成机械过程?

• Build a machine to compute square roots 创造一个机器来计算平方根

– Fixed Program Computers 固定程序计算机 只能执行固定程序

• Calculator 计算器

• Atanasoff and Berry’s (1941) computer for systems of linearequations 阿塔那索夫和贝里在1941面创造的解决联立线性方程的计算机

• Alan Turing’s (1940’s) bombe – decode Enigma codes 阿兰图灵在1940创造的炸弹机——破译恩尼格玛密码

• Use a machine that stores and manipulates instructions 使用一个机器来储存和操作指令

– Stored Program Computer 存储程序计算机

Stored program computer 存储程序计算机

• Sequence of instructions (program) storedinside computer 指令的顺序储存在电脑中

– Built from predefined set of primitive instructions 内置预定义的原始指令集,就像如下的指令

• Arithmetic and logic 算术和逻辑

• Simple tests 简单测试

• Moving data 移动数据

• Special program (interpreter) executeseach instruction in order 特定程序(解释器)按顺序执行每个指令

– Use tests to change flow of control through sequence, to stop whendone 通过一个测试表达式来改变序列控制流,直到测试表达式通过时结束

 

A basic machine architecture 基本的机器架构


注:memory 内存

Control unit 控制单元

Arithmetic logicunit 算术逻辑单元(ALU)

Input 输入

Output 输出

Program counter 程序计数器

Accumulator 累加器

What are the basic primitives? 什么是基本原语

• Turing showed that using six primitives,can compute anything 图灵证明使用六种原语可以做任何计算

– Turing complete 图灵完备性,即具有上述能力的属性

• Fortunately, modern programming languageshave a more convenient set of primitives 幸运的是,现代的编程语言有一个更方便的原语集

• Also have ways to abstract methods tocreate new “primitives”  也可能创造新的原语

• But anything computable in one languageis computable in any other programming language 在一种语言中可以计算的东西在其他语言中也是可以计算的

结论:获取程序性知识,将问题分解为机械性的步骤,然后想办法将这些转化为机械或者计算机能理解的东西,以便计算机执行这些步骤。

1.4 programming language characteristic 编程语言的特点

Creating “recipes”创建‘方法’

• Each programming language provides a setof primitive operations 每个程序设计语言都提供了一套原语集

• Each programming language providesmechanisms for combining primitives to form more complex, but legal,expressions 每个编程语言提供了一种机制,用于组合原语来形成更复杂而且合法的表达式

• Each programming language providesmechanisms for deducing meanings or values associated with computations orexpressions 每个编程语言都提供了一种机制,用于推断或赋予一个计算或表达式意义或价值(赋值运算)

Aspects of languages 编程语言的各个方面

• Primitive constructs 基本元素

– Programming language – numbers, strings, simple operators

–编程语言–数字,字符串,简单的操作符

– English – words

–英语 –单词

• Syntax – which strings of characters andsymbols are well-formed

语法 – 字符串的字符和符号都有很好的组合

– Programming language – we’ll get to specifics shortly, but forexample 3.2 + 3.2 is a valid Python expression

  - 编程语言 - 我们会很快得到细节,但例如3.2 + 3.2是一个有效的Python表达式

– English – “cat dog boy” is not syntactically valid, as not in formof acceptable sentence

- 英语 – “猫狗男孩”不是语法有效,也不是日常可以接受的句子形式

• Static semantics – which syntacticallyvalid strings have a meaning

  静态语义 –有效的有意义的字符串

– English – “I are big” has form<noun><transitive><noun>,so syntactically valid, but is not valid English because “I” is singular, “are”is plural

- 英语 - “我是大”的形式<名词~及物动词~名词>是语法有效的(通顺的句子),但不是正确的英语,因为“我”是单数,“是”是复数

– Programming language – for example, is a valid syntactic form, but2.3/’abc’ is a static semantic error

  编程语言 – 举个例子,2.3/’abc’是一个有效的句法形式,但它是一个静态语义错误

• Semantics – what is the meaningassociated with a syntactically correct string of symbols with no staticsemantic errors

  形式语意(全语义)– 意思是语法正确,没有语意错误的字符串

– English – can be ambiguous  

英语 – 可能是有歧义的

• “I cannot praise this student too highly”

   我不能再表扬这个学生太好了(可以是嘲讽也是极致的赞美)

– Programming languages – always has exactly one meaning

  编程语言 – 有且只有一个意义

• But meaning (or value) may not be what programmer intended

  但是意义(或者价值)可能不是程序员们想要的

结论:

语法:判断一个字符串是否合法。

静态语义:判断一个字符串是否有意义

动态语义:判断一个字符串是否有正确的意义

Where can things go wrong? 哪里可能会出现错误

• Syntactic errors  语法错误

– Common but easily caught by computer  常见,但也容易被电脑发现

• Static semantic errors 静态语义错误

– Some languages check carefully before running, others check whileinterpreting the program 一些语言在运行之前检查,另一些在运行程序的时候检查

– If not caught, behavior of program unpredictable 运行程序时发现的错误,当发生错误是你才知道,你不得不回头找

• Programs don’t have semantic errors, butmeaning may not be what was intended

  语法没有错误,但是可能它表达的意思不是我们想要的

– Crashes (stops running) 崩溃(停止运行)

– Runs forever 一直运行不停止

– Produces an answer, but not programmer’sintent 产生了答案,但并不是程序员想要的

Our goal 我们的目标

• Learn the syntax and semantics of aprogramming language

  学习一种编程方法的语法和语义

• Learn how to use those elements totranslate “recipes” for solving a problem into a form that the computer can useto do the work for us

  学习如何使用这些元素将我们解决问题的“方法”翻译成计算机能够用来为我们工作的形式

• Computational modes of thought enable usto use a suite of methods to solve problems

掌握计算模式的思维,使我们能够使用一系列方法来解决问题

 

总结

在第一讲中,首先学习了计算机能做什么,包括执行计算和存储结果。

然后又学习了知识的类型,包括陈述性知识和程序性知识。陈述性知识是事实的陈述,程序性知识是方法,学习了算法就像菜谱一样是是一系列解决问题的清晰指令。

还学习了基本的机器架构,包括内存,控制单元,运算单元(ALU)三部分。学习了编程的目标是获取程序性知识,将问题分解为机械性的步骤,然后想办法将这些转化为机械或者计算机能理解的东西,以便计算机执行这些步骤。

还学习了编程语言的特点,包括,每个编程语言都提供一套原语集,每个编程语言都可以组合源于形成更复杂的表达式,每个编程语言都都可以赋值运算。还学习了编程语言的各个方面,基本元素(数字,字符串,运算符),语法(判断一个字符串是否违法),静态语义(判断一个字符串是否有意义),形式语义(判断一个字符串是否有正确的意义)。还学习了可能产生错误(bug)的原因:语法错误,静态语义错误,形式语义错误。最后总结了我们的目标,是学习编程语言,并使用它将我们要解决的问题翻译成计算机能够用来为我们工作的形式,还要掌握计算模式思维。

2 0
原创粉丝点击