xiaojuan cai computational thinking 1 lecture 1 introduction xiaojuan cai (蔡小娟)...
TRANSCRIPT
Xiaojuan Cai Computational Thinking 1
Lecture 1
Introduction
Xiaojuan Cai (蔡小娟)
Fall, 2015
Xiaojuan Cai Computational Thinking 2
Before we start
• Pre-course questionnaire
• TA:
• 李春淼 [email protected]
• Course website:
• http://basics.sjtu.edu.cn/~xiaojuan/c
t15/
Xiaojuan Cai Computational Thinking 3
Course policy
• Final score =
• Homework (20%) + PA (20%) + Lab
(10%) + Final exam (50%)
• Practice: Dianxin building 4-313
• Lab sample: percolation
Xiaojuan Cai Computational Thinking 4
Textbook and References
• 程序设计思想与方法 陆朝俊 高等教育出版社
• References:
• [R1] Python Programming: An Introduction to
Computer Science, John Zelle.
• [R2] How to Think Like a Computer Scientist,
Allen Downey, Jeff Elkner and Chris Meyers
• http://basics.sjtu.edu.cn/~xiaojuan/ct15/files/
Xiaojuan Cai Computational Thinking 5
Why this course?• Fundamental part of computer science
• Helps you become a more intelligent user of
computers
• It can be fun!
• Helps the development of problem solving
skills
• Programmers are in great demand!
Xiaojuan Cai Computational Thinking 6
Have fun!
Xiaojuan Cai Computational Thinking 7
Objective• To learn what computer scientists study and
the techniques that they use.
• To understand computer programming
languages.
• To begin using the Python programming
language.
• To learn about chaotic models.
Xiaojuan Cai Computational Thinking 8
Roadmap
• What is computer science?
• Programming languages
• Introduction to Python
• A chaotic model
Xiaojuan Cai Computational Thinking 9
Computing and computer
A computer is a general-purpose device that can be programmed to carry out a set of arithmetic or logical operations automatically.
Computing is any goal-oriented activity requiring, benefiting from, or creating algorithmic processes.
--- Definitions from wikipedia
Xiaojuan Cai Computational Thinking 10
Computing and computer
• Computing can be traced back to 9th
century.
• A first general-purpose computing device
(computer) is invented by Charles Babbage,
in early 19th century.
• A first digital programmable computer is
Colossus (around 1943).
• “Computers are to computer science what telescopes are
to astronomy.”
– E. Dijkstra
Xiaojuan Cai Computational Thinking 11
Computers
Colossus(1943), the first electronic digital programmable computing device. Picture sourced from Wikipedia.
IBM’s Blue Gene/P supercomputer (2011) runs over 250,000 processors. Picture sourced from Wikipedia.
• In 2013, NUDT Tianhe-2 is ranked as the fastest
supercomputer.
Xiaojuan Cai Computational Thinking 12
Computers
• Software (programs) rule the hardware
(the physical machine).
• The process of creating software is
called programming.
• Before programming, we need to
design how to create (the algorithm).
Xiaojuan Cai Computational Thinking 13
Hardware basics
• CPU• the heart of computers• “simple” instructions, fast speed
• Storage• primary – also called RAM, fast but volatile• secondary – permanently, NVRAM, ROM
• I/O device• Mouse, keyboard, display, touch screen
Xiaojuan Cai Computational Thinking 14
Computer science• It is not the study of computers!
It studies “What can be computed?”
• Design – Analysis – Experimentation
• Design = algorithm
• Some problems are unsolvable
• Experimentation: some problems are
intractable
Xiaojuan Cai Computational Thinking 16
Problem solving
• The most important skill
• formulate problems,
• think creatively about solutions, and
• express a solution clearly and accurately
• One level: learn to program
• Another level: learn how to use programs
Xiaojuan Cai Computational Thinking 17
Roadmap
• What is computer science?
• Programming languages
• Introduction to Python
• A chaotic model
Xiaojuan Cai Computational Thinking 18
Programming languages• Natural language has ambiguity
• Programming languages: unambiguous and
precise.
• Every structure in a pl has a precise form:
syntax
• And it has a precise meaning: semantics.
Xiaojuan Cai Computational Thinking 19
Languages of computers• Machine language
• Computer’s language
• Impossible for human beings
• Assembly language
• Possible but still unnatural
• Still useful for designing efficient programs
• High level language
Xiaojuan Cai Computational Thinking 20
High-level to low-level
• Interpreter
• Compiler
• Hybrid compiler/interpreting process
Xiaojuan Cai Computational Thinking 21
GCD in pseudo code
function gcd(a, b) while a ≠ b if a > b
a := a - belse
b := b - a return a
Xiaojuan Cai Computational Thinking 22
GCD in x86 machine language
Xiaojuan Cai Computational Thinking 23
GCD in x86 assembly language
Xiaojuan Cai Computational Thinking 24
GCD in C
Xiaojuan Cai Computational Thinking 25
GCD in Prolog
Xiaojuan Cai Computational Thinking 26
GCD in Scheme
Xiaojuan Cai Computational Thinking 27
GCD in Pythondef gcd(a,b):
while a != b:
if a > b:
a = a - b
else:
b = b - a
return a
Xiaojuan Cai Computational Thinking 28
Roadmap
• What is computer science?
• Programming languages
• Introduction to Python
• A chaotic model
Xiaojuan Cai Computational Thinking 29
Python • Designed by Guido van Rossum
• Predecessor : ABC
• Name origin: Guido is a big fan of
Monty Python's Flying Circus
• Here are some interesting slides from one of my
students in SE352 (programming languages).
Picture sourced from Wikipedia.
Xiaojuan Cai Computational Thinking 30
Python
• Python is an interpreted language
• Command-line mode
• File mode
• “Hello World!” in Python
print “Hello World!”
Xiaojuan Cai Computational Thinking 31
Program
• A program is a sequence of instructions
that specifies how to perform a
computation.
• Instructions include
• input, output, math, conditional execution,
repetition (iteration, recursion), …
Xiaojuan Cai Computational Thinking 32
What is debugging
• Programming errors are called bugs.
• The process of tracking them down and
correcting them is called debugging.
• Errors
• Syntax error
• Semantics error: Run, but not the expected output
• Runtime error: Divide by zero
Xiaojuan Cai Computational Thinking 33
• Let’s play around.
Xiaojuan Cai Computational Thinking 34
Roadmap
• What is computer science?
• Programming languages
• Introduction to Python
• A chaotic model
Xiaojuan Cai Computational Thinking 35
Chaos and computing• Two features:
• For any input, returns 10 seemingly random
numbers between 0 and 1. (chaotic)
• Very small differences in initial value can have
large differences in the output. (butterfly effect)
• The function computed by program has the
general form kx(1-x) where k is 3.9
Xiaojuan Cai Computational Thinking 36
• Input: 0.25• 0.73125• 0.76644140625• 0.698135010439• 0.82189581879• 0.570894019197• 0.955398748364• 0.166186721954• 0.540417912062• 0.9686289303• 0.118509010176
• Input: 0.260.750360.730547494560.7677066257330.69549933390.8259420407340.5606709657210.9606442322820.1474468759350.4902545493760.974629602149
Xiaojuan Cai Computational Thinking 37
Lessons from chaos• This program has import implications.
• Many phenomena in real world exhibit this
kind of chaotic behavior.
• Butterfly effect
• Weather forecast
• Computers may give incorrect answers if there
are very small errors in models or programs.
Xiaojuan Cai Computational Thinking 38
Summary• A computer is a universal information-
processing machine.
• Computer science is the study of what can be computed.
• A computer comprises a CPU, main/secondary memory, and I/O devices.
• Programs are written using a programming language.
Xiaojuan Cai Computational Thinking 39
Summary (cont’d)
• Python is an interpreted language.
• A Python program is a sequence of
statements
• A mathematical model is called chaotic if
very small changes in the input lead to
large changes in the random results.
Xiaojuan Cai Computational Thinking 40
Python
“ 优雅”、“明确”、“简单”周丞
上海交通大学
Xiaojuan Cai Computational Thinking 41
Python 娘简介
• 父亲是吉多·范罗苏姆( Guido van
Rossum )
• 出生于 1991 年。
• 女大十八变,已经历了
幼女期( 1.X 版本)和
萝莉期( 2.X 版本)
目前进入御姐期( 3.X 版本)
还在健康成长着……
Xiaojuan Cai Computational Thinking 42
培养理念(设计哲♂学)
“ 优雅”、“明确”、“简单”
Python 娘
因为家长们不喜欢邻家男孩 Perl 的教育方式“There’s More Than One Way To Do It.”
(不只一种方法来做一件事。)所以 Python 娘受到的教育是“ 用一种方法,最好是只有一种方法来做一件事”
Xiaojuan Cai Computational Thinking 43
特点
• 活泼(动态语言)
• 灵活(“脚本语言”、“胶水语言”)
• 抽象思维(面向对象语言,支持函数式编程)
• 优雅美丽(语法简捷和清晰)
Python 娘
Xiaojuan Cai Computational Thinking 44
• Python 娘很傲骄,御姐状态和萝莉状态变化很大。
( 3.X 版本不兼容 2.X 版本)
• 御姐是未来和希望,但是人们现在更加喜欢萝莉。 BACK