cs249 lecture notes, Fall 2001 Week 1, Thursday Reading: Chapter 1 Read Chapter 1 for Monday. Hand out syllabus. Talk about course alternatives. My lecture notes are on the web page. If you miss class, be sure to pick them up. Useful even if you come to class. http://rocky.wellesley.edu/cs249 Registration 0) which CS class? ----- And we begin... Three threads ------------- 1) MATLAB 2) numerical programming 3) models A model ------- Why is it colder in winter than in summer? Play "what am I leaving out?" A numerical method ------------------ Finding the square root of a. x is my estimate. If x is right, then a/x = x If x is smaller than sqrt(a), then a/x is bigger than sqrt(a). And vice versa. So the answer is always between x and a/x. What's my next guess? How well does it work? High-level languages -------------------- MATLAB is a high-level language, which means that it was designed to be easy for humans to read and right. At first, that claim will seem incredible, but it really is, compared to low level-languages, which are easy for computers to execute. Anyone know another HLL? Used one? General-purpose vs. application-specific HLL. LLLs are machine specific. HLLs are portable. To execute a HLL program, have to translate. 1) Interpretation. Line by line translation. 2) Compilation. Translation all at once. HLL code is called source code. Compiler generates object code or executable. Naming conventions: .c .C .f .java .o .exe What is a program? A sequence of instructions that specifies HOW to perform a computation. Instructions: input, output, simple math, comparison, repetition Specify HOW: in excruciating detail... beginning programmers often have the feeling of teaching an idiot, because the computer seems not to know many things that are obvious to people. Think of it as an exercise in inter-species communication. Computation: More general than just math -- anything a computer can do is considered computation in broad sense. Amazing thing #1: all computations are made up of the same set of simple instructions. Amazing thing #2: compilers are programs that translate other programs, sometimes improving them in the process! Computer Science as a Liberal Art --------------------------------- enumerate the liberal arts liberal arts != humanities Two liberal arts traditions 1) Roman, oratorical, training to be a liber (citizen) cultural literacy! 2) Greek, philosophical, freeing the mind from unexamined ideas critical thinking! By either definition, computer science is a liberal art. 1) You need to know it to be a citizen, and 2) it develops important thinking skills. We are using Java as a tool to develop thinking. Along the way, you will learn to program. But we are not training professional programmers. Natural and formal languages ---------------------------- Nat lang: evolved, people speak it Formal lang: designed, people use it for special purpose Mathematics uses a formal language, chemistry too. Syntax refers to the rules and structure of the language. Semantics refers to the meaning of the language. A syntax error is a statement that is meaningless because it violates the rules of the language: 1) 3+3=6 is syntactically correct, 3=+6\$ is not 2) H2O is correct, 2Zz is not. The statement 3+3=5 is syntactically correct, but semantically incorrect, because what it means is false. The chemical reaction Pb -> Au is syntactically correct, but semantically unlikely. When you read or hear a sentence in English, you unconsciously figure out its structure (nouns, verbs, subjects, objects). This process is called parsing. Errors ------ Is programming a walk in the park? Why, no. Sometimes it is frustrating and unpleasant, like all worthwhile things. Some things that go wrong: 1) Syntax errors: computer is a stickler for spelling and grammar. Syntax errors are discovered by the compiler, and prevent it from generating code. You can't run until you get rid of all the syntax errors. 2) Run-time errors: An unusual condition, like dividing by zero, can cause the program to stop executing at some point. Called "exception" in Java. 3) Logic errors: The program runs, but does not do what you expected. Really, these are not three kinds of errors, but three times when you might detect errors. There is only one kind of error --- the program does not do what you wanted it to do. Why? Because you did not specify the right computation. Computer interprets code quite literally, with no understanding of what you are trying to accomplish. Pedagogic comments: 1) Do the reading. 2) You are learning two languages: MATLAB and CS vocabulary. Of the two, the CS vocabulary is more important. 3) Don't be fooled by common English words. They don't mean what you think. Better if we used Swedish. 4) If you don't understand a lecture, panic immediately. Read the book. Come see me. DON'T WAIT FOR THINGS TO GET BETTER. They won't. 5) Don't take notes.