1.Introduction to Computation and Programing in Python

结构图
结构图

抓住重点即可,不必再过渡去纠缠。

Key quotes

  • And like a good philosophical question, that leads to another, deeper philosophical question.
  • Any interpreter that has that property is what we call Turing complete, which by the way says anything you compute in 1 programming language you can compute in any other programming language.
  • The six basic operations/primitives that gives a language Turing completeness are:*
  1. Right: Move the Machine’s head to the right of the current square
  • Left: Move the Machine’s head to the left of the current square
  • Print: Print a symbol on the current square
  • Scan: Identify any symbols on the current square
  • Erase: Erase any symbols presented on the current square
  • Nothing/halt: Do nothing

思路分析:1.计算机的功能*4 2.算法*4 3.算法应用于计算机*3 4.构成语言的原材料等,初窥编程语言*4

一、Do and limits

第一部分*4: 思路分析:关键词:do and limits

  • 从直观和可得性入手,从身边的电脑入手开始分析,
  • 电脑能做什么?刨根问底,电脑的最基本功能是什么?
  • 电脑能做的仅只是这些吗?还是从帮助直观理解的方面举例,在书中另外阐述了人类的发展曾经受限于计算能力。
  • 进一步追问,只靠简单的计算能力就足够了吗?哪些是计算能力做不了的呢?
  • 收到哪些限制呢?存储,计算速度,实际上受限于算法和数学的局限性

0.Goal:

  • Become skillful at making a computer do what you want it to do
  • Learn computational modes of thinking– Master the art of computational problem solving

1.What does a computer do?

  • Fundamentally a computer:
  • Performs calculations
  • Remembers the results
  • What calculations?
  • Built in primitives
  • Creating our own methods of calculating

2.Is that all it does?

  • A billion calculations per second
  • 100s of gigabytes of storage

3.Are simple calculations enough?

  • Searching the World Wide Web
  • Playing chess
  • Good algorithm design also needed to accomplish a task!

4. So are there limits?

  • Generally Limited by algorithm and capacity
  • Despite its speed and storage, a computer does have limitations
  • Some problems still too complex
  • Accurate weather prediction at a local scale
  • Cracking encryption schemes
  • Some problems are fundamentally impossible to compute
    • Predicting whether a piece of code will always halt with an answer for any input

二、算法

第二部分*4 关键词:算法

  • 思路分析:解释Computational Thikning和算法

5.Computational problem solving

  • What is computation?

And like a good philosophical question, that leads to another, deeper philosophical question.

  • What is knowledge?
  • Declarative knowledge
  • Statements of fact
  • Imperative knowledge
  • “how to” methods or recipes

6.Declarative knowledge

  • “The square root of a number x is a number y such that y*y = x”
  • Can you use this to find the square root of a particular instance of x?

7.Imperative knowledge

  • Here is a “recipe” for deducing a square root of a number x – attributed to Heron of Alexandria in the first century AD
    • Start with a guess, called g
    • If g*g is close enough to x, stop and say that g is the answer Otherwise make a new guess, by averaging g and x/g
    • Using this new guess, repeat the process un(l we get close enough

8.Algorithms are recipes

  1. Put custard mixture over heat
  2. Str
  3. Dip spoon in custard
  4. Remove spoon and run finger across back of spoon
  5. If clear path is leU, remove custard from heat and let cool
  6. Otherwise repeat from step 2

三、算法在机器中的应用

第三部分*3 算法在电路和电子设备的最高级成果——计算机中的应用

9.How do we <u>capture</u> 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 linear equations
      • Alan Turing’s (1940’s) bombe – decode Enigma codes
  • Use a machine that stores and manipulates instructions
    • Stored Program Computer

10.Stored program computer

  • Sequence of instructions (program) stored inside computer

    • Built from predefined set of primitive instructions
      • Arithmetic and logic
      • Simple tests
      • Moving data
  • Special program (interpreter) executes each instruction in order

    • Use tests to change flow of control through sequence, to stop when done

    这里的test是编程的关键,Conditional和Iterate都要用到Test

11.A basic machine architecture

四、编程语言的构成

第四部分*4:初窥编程语言

12.What are the basic primitives?

  • Turing showed that using six primitives, can compute anything
  • Turing complete
  • Fortunately, modern programming languages have a more convenient set of primitives
  • Also have ways to abstract methods to create new “primitives”
  • But anything computable in one language is computable in any other programming language.

That is amazing!!!

13.Creating “recipes”

  • Each programming language provides a set of primitive operations
  • Each programming language provides mechanisms for combining primitives to form more complex, but legal, expressions
  • Each programming language provides mechanisms for deducing meanings or values associated with computations or expressions

14.Aspects of languages

  • Primitive constructs
    • Programming language – numbers, strings, simple operators
    • English – words
  • Syntax – which strings of characters and symbols are well-formed
    • Programming language – we’ll get to specifics shortly, but for example 3.2 + 3.2 is a valid Python expression
    • English – “cat dog boy” is not syntactically valid, as not in form of acceptable sentence
  • Static semantics – which syntactically valid strings have a meaning
    • English – “I are big” has form <noun> <intransitive verb> <noun>, so syntactically valid, but is not valid English because “I” is singular, “are” is plural
    • Programming language – for example, <literal> <operator> <literal> is a valid syntactic form, but 2.3/’abc’ is a static semantic error
  • Semantics – what is the meaning associated with a syntactically correct string of symbols with no static semantic 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

15.Where can things go wrong?

  • Syntactic errors
  • Common but easily caught by computer
  • Static semantic errors
    • Some languages check carefully before running, others check while interpreting the program
    • If not caught, behavior of program unpredictable
  • • Programs don’t have semantic errors, but meaning may not be what was intended
    • – Crashes (stops running)
    • – Runs forever– Produces an answer, but not programmer’s intent

16.Our Goal

  • Learn the syntax and semantics of a programming language
  • Learn how to use those elements to translate “recipes” for solving a problem into a form that the computer can use to do the work for us
  • Computational modes of thought enable us to use a suite of methods to solve problems
草稿图
草稿图
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,937评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,503评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,712评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,668评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,677评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,601评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,975评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,637评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,881评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,621评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,710评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,387评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,971评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,947评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,189评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,805评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,449评论 2 342

推荐阅读更多精彩内容