Upload
vanthu
View
212
Download
0
Embed Size (px)
Citation preview
Start to CodeInstructor: Xiao Liu
IntroductionXiao Liu
Third-year Ph.D. Candidate
@ Information Sciences and Technology
Penn State University, University Park
Research Interests:
Programming Languages
Software Engineering & Security
Why coding?
Applications
Today● Course Info● What does a computer do● Turing Machine
Course Information● Basics about Programming
○ Statement○ Branching○ Loop○ Functions
● Computational Thinking○ Sorting○ Searching○ Parallel Processing
● Programming an Artifact○ Design & Implementation○ Testing & Debugging○ Summarization
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law■ Double every 18 months
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law■ Double every 18 months■ 10,000,000,000 cal/sec
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law■ Double every 18 months■ 10,000,000,000 cal/sec
1 + 2 - 10 + 11 + 7 - 6 - 4 + 22 - 1
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register■ Cache■ Memory■ Hard Disk
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register - 32 bits 00000000111111110000000011111111■ Cache ■ Memory■ Hard Disk
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register - 32 bits 00000000111111110000000011111111■ Cache - 256 KB (65,536 * size of Register)■ Memory ■ Hard Disk
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register - 32 bits 00000000111111110000000011111111■ Cache - 256 KB (65,536 * size of Register)■ Memory - 8 MB (32 * size of Cache)■ Hard Disk - 256 GB (32,768 * size of Memory)
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register - 32 bits 00000000111111110000000011111111■ Cache - 256 KB (65,536 * size of Register)■ Memory - 8 MB (32 * size of Cache)■ Hard Disk - 256 GB (32,768 * size of Memory)
Size Increase
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register - 32 bits 00000000111111110000000011111111■ Cache - 256 KB (65,536 * size of Register)■ Memory - 8 MB (32 * size of Cache)■ Hard Disk - 256 GB (32,768 * size of Memory)
Why not store everything in Hard Disk?
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register - 1 CPU clock cycle, 2 GHz, 2,000,000,000 access/sec ■ Cache - ?■ Memory - ?■ Hard Disk - ?
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
■ Register - 1 CPU clock cycle, 2 GHz, 2,000,000,000 access/sec ■ Cache - 100 GB/second ■ Memory - 10 GB/sec ■ Hard Disk - 2000 MB/second
Speed Increase
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?○ +, - , *, /○ Any more?
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?○ +, - , *, /○ Turing Machine - Most General Model about Computing
Alan Turing (1912-1954)
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?○ +, - , *, /○ Turing Machine
■ Read the symbol on the square under the head.■ Edit the symbol by writing a new symbol or erasing it.■ Move the tape left of right by one square so that the machine can read and edit the
symbol on a neighbouring square.
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?○ +, - , *, /○ Turing Machine
Symbol read Write instruction Move instructionBlank None None0 Write 1 Move tape to the right1 Write 0 Move tape to the right
The current symbol under the head is 0, so we write a 1 and move the tape right by one square.
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?○ +, - , *, /○ Turing Machine
Symbol read Write instruction Move instructionBlank None None0 Write 1 Move tape to the right1 Write 0 Move tape to the right
The symbol being read is now 1, so we write a 0 and move the tape right by one square:
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?○ +, - , *, /○ Turing Machine
Symbol read Write instruction Move instructionBlank None None0 Write 1 Move tape to the right1 Write 0 Move tape to the right
Similarly, the symbol read is a 1, so we repeat the same instructions.
What does a Computer do● Fundamentally
○ Calculation - Moore’s Law○ Storage - Different levels
● What kind of calculations?○ +, - , *, /○ Turing Machine
Symbol read Write instruction Move instructionBlank None None0 Write 1 Move tape to the right1 Write 0 Move tape to the right
Similarly, the symbol read is a 1, so we repeat the same instructions.
Lab 1: Try A Turing Simulatorhttps://turingmachinesimulator.com/
Even Number of Zeros
q0, 0q1, 0, >
Current State
Symbol Read
Next State
Symbol Write
Move
Lab 1: Try A Turing SimulatorHow to modify this into
Odd Number of Zeros?