Computers and programming languages introduction

Similar documents
CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

CS1100 Introduction to Programming

CVEN 302. Computer Applications in Engineering and Construction. Dr. Tony Cahill Environmental and Water Resources Division

Numerical Methods in Physics. Lecture 1 Intro & IEEE Variable Types and Arithmetic

Practical Numerical Methods in Physics and Astronomy. Lecture 1 Intro & IEEE Variable Types and Arithmetic

Physics 331 Introduction to Numerical Techniques in Physics

Today. An Animated Introduction to Programming. Prerequisites. Computer programming

Programming. Dr Ben Dudson University of York

CS 536. Class Meets. Introduction to Programming Languages and Compilers. Instructor. Key Dates. Teaching Assistant. Charles N. Fischer.

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

Introduction to Scientific Computing Lecture 1

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2015 Euiseong Seo

Number Representation 3/2/01 Lecture #

CS120 Computer Science I. Instructor: Jia Song

Numerical computing. How computers store real numbers and the problems that result

CMPE012 Computer Engineering 12 (and Lab) Computing Systems and Assembly Language Programming. Summer 2009

Up next. Midterm. Today s lecture. To follow

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

A Balanced Introduction to Computer Science

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Administration Computers Software Algorithms Programming Languages

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

You must pass the final exam to pass the course.

What we need to know about error: Class Outline. Computational Methods CMSC/AMSC/MAPL 460. Errors in data and computation

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

MATH 353 Engineering mathematics III

EECE 321: Computer Organization

ESET 349 Microcontroller Architecture, Fall 2018

CS240: Programming in C

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CSC 101: Lab Manual#9 Machine Language and the CPU (largely based on the work of Prof. William Turkett) Lab due date: 5:00pm, day after lab session

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

Operating Systems, Spring 2015 Course Syllabus

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Computational Methods CMSC/AMSC/MAPL 460. Representing numbers in floating point and associated issues. Ramani Duraiswami, Dept. of Computer Science

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering?

Introduction to Functional Programming. Slides by Koen Claessen and Emil Axelsson

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic

Introduction to Data Structures

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

COMP Data Structures

ESET 369 Embedded Systems Software, Fall 2017

COMP Data Structures

2 Computation with Floating-Point Numbers

Introduction to Computer Systems

Microprocessor. Dr. Rabie A. Ramadan. Al-Azhar University Lecture 1

INFS 214: Introduction to Computing

Floating-point representation

Course and Contact Information. Course Description. Course Objectives

CS 61C: Great Ideas in Computer Architecture Performance and Floating Point Arithmetic

Computer Systems C S Cynthia Lee

Today CISC124. Building Modular Code. Designing Methods. Designing Methods, Cont. Designing Methods, Cont. Assignment 1 due this Friday, 7pm.

FLOATING POINT NUMBERS

Topic 1: Introduction

Outline. What is Performance? Restating Performance Equation Time = Seconds. CPU Performance Factors

CS 61C: Great Ideas in Computer Architecture Performance and Floating-Point Arithmetic

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD

ESET 369 Embedded Systems Software, Spring 2018

Foundations of Computer Systems

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1, 2, and 3, Spring 2018

COMP Overview of Tutorial #2

Administrivia. CMSC 216 Introduction to Computer Systems Lecture 24 Data Representation and Libraries. Representing characters DATA REPRESENTATION

Course and Contact Information. Course Description. Course Objectives

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

Roundoff Errors and Computer Arithmetic

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

EECE.2160: ECE Application Programming Spring 2017

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

Introduction to Computer Systems

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Chapter 1. Numeric Artifacts. 1.1 Introduction

3.1 DATA REPRESENTATION (PART C)

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Digital Computers and Machine Representation of Data

Programming (Econometrics)

COSE212: Programming Languages. Lecture 0 Course Overview

Course and Unix Intro

COMP 401 COURSE OVERVIEW

History of Computing. Ahmed Sallam 11/28/2014 1

AE Computer Programming for Aerospace Engineers

Compilers for Modern Architectures Course Syllabus, Spring 2015

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

2 Computation with Floating-Point Numbers

General Course Information. Catalogue Description. Objectives

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes

Chapter Three. Arithmetic

Independent Representation

Introduction to Software Development (ISD) David Weston and Igor Razgon

Principles of computer programming. Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković

CSC258: Computer Organization. Memory Systems

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Dr. Chuck Cartledge. 15 July 2015

General Instructions. You can use QtSpim simulator to work on these assignments.

Programming Languages and Compilers. Jeff Nucciarone AERSP 597B Sept. 20, 2004

Number Representations

CS 375 UNIX System Programming Spring 2014 Syllabus

Lecture 1. Course Overview Types & Expressions

Transcription:

Computers and programming languages introduction Eugeniy E. Mikhailov The College of William & Mary Lecture 01 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 1 / 19

Class goals and structure Primary purpose learn to to specify a problem break it up into algorithmic pieces implement a program to execute these pieces learn Matlab Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 2 / 19

Class goals and structure Primary purpose learn to to specify a problem break it up into algorithmic pieces implement a program to execute these pieces learn Matlab Structure first we learn basics of Matlab as programming language (couple weeks) then learn numerical analysis basics while keep mastering Matlab Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 2 / 19

Class goals and structure Primary purpose learn to to specify a problem break it up into algorithmic pieces implement a program to execute these pieces learn Matlab Structure first we learn basics of Matlab as programming language (couple weeks) then learn numerical analysis basics while keep mastering Matlab Weekly schedule Monday, Wednesday: normal lecture hours Friday: short lecture, lab, hands on Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 2 / 19

Building blocks Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 3 / 19

Building blocks To learn a language we need to practice and use this language a lot of weight on homeworks and projects Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 3 / 19

Building blocks To learn a language we need to practice and use this language a lot of weight on homeworks and projects No final exam Final project defense instead December 14 at 14:00 in Small Hall 233 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 3 / 19

Building blocks To learn a language we need to practice and use this language a lot of weight on homeworks and projects No final exam Final project defense instead December 14 at 14:00 in Small Hall 233 Grades contribution Homeworks: 15% Midterm projects: 60% Final project: 25% Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 3 / 19

Building blocks To learn a language we need to practice and use this language a lot of weight on homeworks and projects No final exam Final project defense instead December 14 at 14:00 in Small Hall 233 Grades contribution Homeworks: 15% Midterm projects: 60% Final project: 25% Assignments and lecture notes will be posted on my homepage http://physics.wm.edu/ evmik/ Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 3 / 19

Homeworks and midterm project deadlines due date: corresponding Monday at 1:00pm for email submission report to be submitted via email as well as a carbon copy to be collected at the beginning of the Monday class if there is no listings and no algorithms/data files you will get zero points. Late submission penalties For each consequent day after due date there will be a penalty (10% out of maximum possible score). Even if submission happens 1 minute after due date, it holds 1 day penalty. Projects homework preparation recommendation Do not wait till the last day to finish your exercise. Programs almost never work at the first try and require quite a lot of time to debug. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 4 / 19

Collaboration and grading scale Collaborations are not permitted for homeworks. Projects to be done in group of 2 or 3 persons. This is the time to actively discuss and cooperate. Only one report per such group is needed. But everyone expected to have a full understanding of the project. Be ready to answer questions related to the project without your group support. Grading scale Grade percentage Grade percentage Grade percentage A 94-100 A- 90-94 B+ 87-90 B 84-87 B- 80-84 C+ 77-80 C 74-77 C- 70-74 D+ 67-70 D 64-67 D- 60-64 F <60 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 5 / 19

Recommended reading Everything required during this class will be provided during lecture times. Two optional books for your own references. A short Matlab reference book: "Getting Started with MATLAB: A Quick Introduction for Scientists and Engineers" bu Rudra Pratap ISBN-10: 0199731241 ISBN-13: 978-0199731244 A more extended treatment of numerical algorithm with Matlab: "Numerical Methods in Engineering with MATLAB" by Jaan Kiusalaas ISBN-10: 0521191335 ISBN-13: 978-0521191333 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 6 / 19

Early history of computing Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 7 / 19

Early history of computing Computers use to be humans Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 7 / 19

Early history of computing Computers use to be humans Computing aids - no programing possible abacus sliding ruler pre-calculated tables of function (logarithm, trigonometry... ) mechanical calculators Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 7 / 19

Early history of computing Computers use to be humans Computing aids - no programing possible abacus sliding ruler pre-calculated tables of function (logarithm, trigonometry... ) mechanical calculators Modern computers appear at 1946 -ENIAC (Electronic Numerical Integrator And Computer) weight: 30 tons cost: $500,000 ($6,000,000 adjusted) power consumption: 150 kw Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 7 / 19

ENIAC vs modern PC Speed operations per second ENIAC 5000 additions 357 multiplications 38 divisions Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 8 / 19

ENIAC vs modern PC Speed operations per second ENIAC 5000 additions 357 multiplications 38 divisions Athlon 3000+ (2GHz) 70,000,000 additions 70,000,000 multiplications 50,000,000 divisions 15,000,000 sin operations Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 8 / 19

Common features of modern computer Central Processing Unit (CPU) memory holds data and executable code data input and output same hardware can do different calculation sequences usually use binary system programmable for any general task Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 9 / 19

Common features of modern computer Central Processing Unit (CPU) memory holds data and executable code data input and output same hardware can do different calculation sequences usually use binary system programmable for any general task Speed measured in FLOPS (the number of floating point operations per second) which usually proportional to the clock frequency. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 9 / 19

Common features of modern computer Central Processing Unit (CPU) memory holds data and executable code data input and output same hardware can do different calculation sequences usually use binary system programmable for any general task Speed measured in FLOPS (the number of floating point operations per second) which usually proportional to the clock frequency. Different computer architectures (AMD, Mac, Intel, ARM... ) have different proportionality coefficient. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 9 / 19

Common features of modern computer Central Processing Unit (CPU) memory holds data and executable code data input and output same hardware can do different calculation sequences usually use binary system programmable for any general task Speed measured in FLOPS (the number of floating point operations per second) which usually proportional to the clock frequency. Different computer architectures (AMD, Mac, Intel, ARM... ) have different proportionality coefficient. My 2 GHz AMD PC can do about 50 MegaFLOPS Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 9 / 19

Computers... Computers are incredibly fast, Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Computers... Computers are incredibly fast, accurate, and Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Computers... Computers are incredibly fast, accurate, and stupid. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Computers... Computers are incredibly fast, accurate, and stupid. Humans beings are incredibly slow, Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Computers... Computers are incredibly fast, accurate, and stupid. Humans beings are incredibly slow, inaccurate, Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Computers... Computers are incredibly fast, accurate, and stupid. Humans beings are incredibly slow, inaccurate, and brilliant. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Computers... Computers are incredibly fast, accurate, and stupid. Humans beings are incredibly slow, inaccurate, and brilliant. Together they are powerful beyond imagination. Leo Cherne (1969) Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Computers... Thus Computers are incredibly fast, accurate, and stupid. Humans beings are incredibly slow, inaccurate, and brilliant. Together they are powerful beyond imagination. Leo Cherne (1969) Computer is not a substitute for a brain Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 10 / 19

Programming languages overview There are hundreds programming languages. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 11 / 19

Programming languages overview There are hundreds programming languages. Super low-level language binary code the only thing which computers understand each instruction looks like a number usually it is not human readable Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 11 / 19

Programming languages overview There are hundreds programming languages. Super low-level language binary code the only thing which computers understand each instruction looks like a number usually it is not human readable low-level languages assembler (human readable binary code translation) Fortran, LISP, C, C++, Fort Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 11 / 19

Programming languages overview There are hundreds programming languages. Super low-level language binary code the only thing which computers understand each instruction looks like a number usually it is not human readable low-level languages assembler (human readable binary code translation) Fortran, LISP, C, C++, Fort higher-level languages Tcl, Java, JavaScript, PHP, Perl, Python Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 11 / 19

Programming languages overview There are hundreds programming languages. Super low-level language binary code the only thing which computers understand each instruction looks like a number usually it is not human readable low-level languages assembler (human readable binary code translation) Fortran, LISP, C, C++, Fort higher-level languages Tcl, Java, JavaScript, PHP, Perl, Python Unfortunately none of them serves all needs. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 11 / 19

Programming languages implementations Compiled generate computers binary code it takes time faster execution time a bit harder to debug if you find and fixed an error (bug) you need to recompile Examples: Assembler, C, C++, Fortran Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 12 / 19

Programming languages implementations Compiled generate computers binary code it takes time faster execution time a bit harder to debug if you find and fixed an error (bug) you need to recompile Examples: Assembler, C, C++, Fortran Interpreted No compilation interpretation to machine code per instruction slow (since you have to interpret same instruction over and over) cross-platform code Examples: Perl, JavaScript, Lua, Php, Tcl, Shells, Matlab Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 12 / 19

Programming languages implementations Compiled generate computers binary code it takes time faster execution time a bit harder to debug if you find and fixed an error (bug) you need to recompile Examples: Assembler, C, C++, Fortran just-in-time compilation middle ground compile once to bytecode cross-platform Examples: Java, Python Interpreted No compilation interpretation to machine code per instruction slow (since you have to interpret same instruction over and over) cross-platform code Examples: Perl, JavaScript, Lua, Php, Tcl, Shells, Matlab Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 12 / 19

Matlab as a language of choice Matlab (matrix laboratory) Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 13 / 19

Matlab as a language of choice Matlab (matrix laboratory) Pro interpreted easy to use and debug quite fast if done right, since main functions are compiled large selection of scientific related functions built in graphics/plotting Turing complete (you can do with it everything which computer is capable) designed to do numerical calculations Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 13 / 19

Matlab as a language of choice Matlab (matrix laboratory) Pro interpreted easy to use and debug quite fast if done right, since main functions are compiled large selection of scientific related functions built in graphics/plotting Turing complete (you can do with it everything which computer is capable) designed to do numerical calculations Contra interpreted could be slow if programmed inefficiently Not free to modify internals quite fast since for main functions it calls a compiled code rudimentary symbolic calculations Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 13 / 19

Matlab: where to get Free for W&M students available for Mac and Windows visit http://www.wm.edu/offices/it/a-z/software/index.php choose appropriate Math & Statistics Software section download Matlab Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 14 / 19

Matlab: where to get Free for W&M students available for Mac and Windows visit http://www.wm.edu/offices/it/a-z/software/index.php choose appropriate Math & Statistics Software section download Matlab Please, do it before this Friday class, also do not forget to bring your notebook with you for Friday classes. Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 14 / 19

Discretization - The main weakness of computers coming from resources limitation For example: 1/6 = 0.1666666666666666 But computer has limited amount of memory. Thus it cannot hold infinite amount of digits and has to truncate somewhere. Let s say it can hold only 4 significant digits. 1/6 = 0.6667 c This called round off error due to truncation/rounding. Then for computer 1/6 = 1/5.9999 or 0.1667123 = 0.1667321 = 0.1667222 = 0.1667111 or even more interesting 20 (1/6) 20/6 = 20 0.1667 3.333 = 3.334 3.333 = 10 4 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 15 / 19

Binary representation - why PHYS 256 Modern general purpose computers use binary representation bit is a smallest unit of information bit value is either 0 or 1 Bit is too small so we use byte byte = 8 bits stitched together byte can represent values in the range 128 0 127 the major (the left most) but usually holds the sign (s) of the number 0: means positive 1: means negative 01001010 2 decimal representation 01001010 2 = ( 1) 0 (0 2 0 + 1 2 1 + 0 2 2 + 1 2 3 + 0 2 4 + 0 2 5 + 1 2 6 ) = 2 + 8 + 64 =74 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 16 / 19

Binary representation (cont.) Byte is clearly to small to be used for real life computation. Matlab uses 8 bytes or 64 bits for number representation available range 2, 147, 483, 648 0 2, 147, 483, 647 you can find this range by executing intmin and intmax notice that you cannot use numbers outside of this range 2, 147, 483, 647 + 10 = 2, 147, 483, 647 this is called overflow error Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 17 / 19

Float numbers representation What to do if you need to store a float number? Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 18 / 19

Float numbers representation What to do if you need to store a float number? For example 123.765 10 12 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 18 / 19

Float numbers representation What to do if you need to store a float number? For example 123.765 10 12 First convert it to scientific notation 1.23765 10 14 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 18 / 19

Float numbers representation What to do if you need to store a float number? For example 123.765 10 12 First convert it to scientific notation 1.23765 10 14 truncate it to certain number of significant digits let use 4 for example (actually 17 decimals for 64 bits float number) 1.237 10 14 Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 18 / 19

Float numbers representation What to do if you need to store a float number? For example 123.765 10 12 First convert it to scientific notation 1.23765 10 14 truncate it to certain number of significant digits let use 4 for example (actually 17 decimals for 64 bits float number) 1.237 10 14 resulting number should have a form ( 1) s c b q where s is a sign bit (1 in our case) c is mantissa or coefficient (1.237) b is the base (10) q is the exponent (14) Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 18 / 19

Float numbers representation What to do if you need to store a float number? For example 123.765 10 12 First convert it to scientific notation 1.23765 10 14 truncate it to certain number of significant digits let use 4 for example (actually 17 decimals for 64 bits float number) 1.237 10 14 resulting number should have a form ( 1) s c b q where s is a sign bit (1 in our case) c is mantissa or coefficient (1.237) b is the base (10) q is the exponent (14) Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 18 / 19

Float numbers representation What to do if you need to store a float number? For example 123.765 10 12 First convert it to scientific notation 1.23765 10 14 truncate it to certain number of significant digits let use 4 for example (actually 17 decimals for 64 bits float number) 1.237 10 14 resulting number should have a form ( 1) s c b q where s is a sign bit (1 in our case) c is mantissa or coefficient (1.237) b is the base (10) q is the exponent (14) Computers internally use binary base b = 2 64 bits for full representation 52+1 bits for mantissa (about 17 decimal digits) 11 bits for exponent (±307) Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 18 / 19

Limits of the float representation maximum ±1.797693134862316 10 308 (use realmax in Matlab) (1.797693134862316 10 308 ) 10 = Inf overflow error minimum ±2.225073858507201 10 308 (use realmin in Matlab) (2.225073858507201 10 308 )/10 = 0 underflow problem truncation error 1.797693134862316 + 20 = 21.797693134862318 1.797693134862316 + 100 = 101.7976931348623 how to mitigate try to use numbers of the similar magnitude do not rely on the least significant digits Eugeniy Mikhailov (W&M) Practical Computing Lecture 01 19 / 19