Lecture 2: Formal Systems and Languages MU! CS200: Computer Science University of Virginia Computer Science David Evans http://www.cs.virginia.edu/evans Menu • Questions from Lecture 1 Notes • Course Expectations • Formal Systems – MIU-system • Languages – English – Scheme 16 January 2004 CS 200 Spring 2004 2 If it takes 60 seconds to compute a photomosaic for Problem Set 1 today on a typical PC, estimate how long it will take CS200 students in 2007 to compute the same photomosaic? How long will it take in 2010? > (/ (* (- 2007 2004) 12) 18) 2 Difference in years * 12 = number of months Number of months / 18 = number of doublings > (/ 60 (* 2 2)) according to Moore’s Law 15 > (/ (* (- 2010 2004) 12) 18) 60 seconds today, 2 doublings by 2007 4 15 seconds in 2007 > (/ 60 (* 2 2 2 2)) 15/4 > (exact->inexact (/ 60 (* 2 2 2 2))) 3.75 60 seconds today, 4 doublings by 2010 3.75 seconds in 2010 16 January 2004 CS 200 Spring 2004 3 Are there any non-recursive natural languages? What would happen to a society that spoke one? Not for humans at least. They would run out of original things to say. Chimps and Dolphins are able to learn nonrecursive “languages” (some linguists argue they are not really “languages”), but only humans can learn recursive languages. 16 January 2004 CS 200 Spring 2004 4 Running out of Ideas “Its all been said before.” Eventually true for a non-recursive language. Never true for a recursive language. There is always something original left to say! 16 January 2004 CS 200 Spring 2004 5 Course Expectations 16 January 2004 CS 200 Spring 2004 6 Course Roadmap 16 January 2004 CS 200 Spring 2004 Liberal Arts Illiberal Arts (Intellectual) ($$$$) Computer Science 1st Class from Euclid and Ada to PS 1-6 Quantum Computing PS 7 and the World Wide Web PS 8 7 What You Should Expect • The fourth (?) coolest class at UVa – Less cool than PHYE162, PHYE163, PHYE164 16 January 2004 CS 200 Spring 2004 You should expect these of all your classes! • This course will be consistent with the original notion of a Liberal Arts education • This course will be as consistent as possible with Mr. Jefferson’s vision for the University 8 Like Drinking from a Firehose It may hurt a little bit, and a lot of water will go by you, but you won’t go away thirsty! 16 January 2004 CS 200 Spring 2004 9 Help Available • Me: David Evans (Call me “Dave” or “Coach”) – Office Hours (Weds after class, Thurs 4-5pm) – Always available by email, if I don’t reply in 24 hours, send again and complain • Assistant Coaches: staffed lab hours in Small Hall Sarah Bergkuist, Andrew Connors, Patrick Rooney, Katie Winstanley • Web site: http://www.cs.virginia.edu/cs200 – Everything goes on the web, you should visit it often • Your classmates (read the course pledge carefully!) 16 January 2004 CS 200 Spring 2004 10 What I Expect of You 1. Everything on the Course Pledge – You should actually read it not just sign it (you will lose points on PS1 if your submissions reveals that you didn’t read it!) 2. You are a “Jeffersonian Student” 1. Believe knowledge is powerful 2. Interested in lots of things, ahead of your time 3. Want to use what you learn to do good things 4. Care more about what you learn than grades and degree requirements 16 January 2004 CS 200 Spring 2004 11 Background Expected • Language: – Reasonable reading and writing in English – Understanding of subject, verb and object • Math: – Whole numbers, add, subtract, multiply, divide – Exponentiation, logarithms (we will review) • Logic: and, or, not • Computer Literacy: read email, browse web If I ever appear to expect anything else, stop me! 16 January 2004 CS 200 Spring 2004 12 A Course for Everyone! • CLAS, SEAS, Commerce, Arch, etc. • 1st, 2nd, 3rd, 4th, 5th Years, Community Scholars, Faculty • No background expected…but challenging even for students with lots of previous CS courses (if you’ve already taken CS655 or CS415 talk to me first) • Computer Science (future-) majors…but worthwhile even if you don’t take another CS course Need to get course action signed by Monday! 16 January 2004 CS 200 Spring 2004 13 Survey Results • Previous Programming: None at all (8), A little (7), one or two courses (7), lots (5) • Years: 1st (4), 2nd (4), 3rd (13), 4th (4) • Majors: Art, Biology, Biomedical Business, Engineering, Cognitive Science (7), Computer Science (5), Electrical Engineering (2), English, Media Studies, Psychology (2), Systems (3), Undecided (5) • I will post a details on the web site this weekend (including my answers to your questions) 16 January 2004 CS 200 Spring 2004 14 Three Most Important Attributes To Do Well • Open Mind – Much of this course is about learning a new way of thinking • Persistence – Don’t expect to understand everything the first (or second or third) time you see it – Don’t give up if you can’t find the answer in the book or notes (most questions will require you to think!) • Willingness to spend time in Small Hall – Benefit from staffed lab hours and working with classmates 16 January 2004 CS 200 Spring 2004 15 Any Logistics Questions? Next: Formal Systems 16 January 2004 CS 200 Spring 2004 16 Formal Systems • Set of symbols – Starting Points – Primitives • Set of rules for manipulating symbols – Hofstadter: Rules of Production, Rules of Inference – Also: Rules of Combination 16 January 2004 CS 200 Spring 2004 17 The MIU System • Symbols: M, I, U • Rules of Production: – Rule I: If you have a string ending in I, you can add a U at the end. – Rule II: Suppose you have Mx. Then you may add Mxx to your collection. – Rule III: If III occurs in one of the strings in your collection you may make a new string with U in place of III. – Rule IV: If UU occurs inside one of your strings, you can drop it. 16 January 2004 CS 200 Spring 2004 18 MIU System Example Start with MUI, produce MIU Rules of Production: Rule I: If you have a string ending in I, you can add a U at the end. Rule II: Suppose you have Mx. Then you may add Mxx to your collection. Rule III: If III occurs in one of the strings in your collection you may make a new string with U in place of III. Rule IV: If UU occurs inside one of your strings, you can drop it. 16 January 2004 CS 200 Spring 2004 19 Languages 16 January 2004 CS 200 Spring 2004 20 What is a language? Webster: A systematic means of communicating ideas or feelings by the use of conventionalized signs, sounds, gestures, or marks having understood meanings. 16 January 2004 CS 200 Spring 2004 21 Linguist’s Definition (Charles Yang) A description of pairs (S, M), where S stands for sound, or any kind of surface forms, and M stands for meaning. A theory of language must specify the properties of S and M, and how they are related. 16 January 2004 CS 200 Spring 2004 22 Languages and Formal Systems What is the difference between a formal system and a language? With a language, the surface forms have meaning. 16 January 2004 CS 200 Spring 2004 23 What are languages made of? • Primitives (almost all languages have these) – The simplest surface forms with meaning • Means of Combination (all languages have these) – Like Rules of Production for Formal Systems – Ways to make new surface forms from ones you already have • Means of Abstraction (all powerful languages have these) – Ways to use simple surface forms to represent complicated ones 16 January 2004 CS 200 Spring 2004 24 Does English have these? • Primitives – Words (?) • e.g., “antifloccipoccinihilipilification” – not a primitive – Morphemes – smallest units of meaning • e.g., anti- (“opposite”) • Means of combination – e.g., Sentence ::= Subject Verb Object – Precise rules, but not the ones you learned in grammar school Ending a sentence with a preposition is something up with which we will not put. Winston Churchill 16 January 2004 CS 200 Spring 2004 25 Does English have these? • Means of abstraction – Pronouns: she, he, it, they, which, etc. – Confusing since they don’t always mean the same thing, it depends on where they is used. The “these” in the slide title is an abstraction for the three elements of language introduced 2 slides ago. The “they” in the confusing sentence is an abstraction for pronouns. 16 January 2004 CS 200 Spring 2004 26 How should we describe languages? Detour: History of Computer Programming 16 January 2004 CS 200 Spring 2004 27 ENIAC: Electronic Numerical Integrator and Computer • Early computer (but not the world’s first) [1946] • Built to calculate bombing tables Memory size: twenty 10 decimal digit accumulators = 664 bits ENIAC (1946): ½ mm Apollo Guidance Computer (1969): 1 inch You: 2.3 miles 16 January 2004 CS 200 Spring 2004 28 Directions for Getting 6 1. Choose any regular accumulator (ie. Accumulator #9). 2. Direct the Initiating Pulse to terminal 5i. 3. The initiating pulse is produced by the initiating unit's Io terminal each time the Eniac is started. This terminal is usually, by default, plugged into Program Line 1-1 (described later). Simply connect a program cable from Program Line 1-1 to terminal 5i on this Accumulator. 4. Set the Repeat Switch for Program Control 5 to 6. 5. Set the Operation Switch for Program Control 5 to . 6. Set the Clear-Correct switch to C. 7. Turn on and clear the Eniac. 8. Normally, when the Eniac is first started, a clearing process is begun. If the Eniac had been previously started, or if there are random neons illuminated in the accumulators, the ``Initial Clear'' button of the Initiating device can be pressed. 9. Press the ``Initiating Pulse Switch'' that is located on the Initiating device. 10.Stand back. http://www.seas.upenn.edu/~museum/qman/node6.html 16 January 2004 CS 200 Spring 2004 Page is now missing unfortunately. 29 Admiral Grace Hopper (1906-1992) “Nobody believed that I had a running compiler and nobody would touch it. They told me computers could only do arithmetic.” 16 January 2004 • Mathematics PhD Yale, 1934 • Entered Navy, 1943 • First to program Mark I (first “large” computer, 51 feet long) • Wrote first compiler (1952) – program for programming computers • Co-designer of COBOL (most widely used programming language until a few years ago) CS 200 Spring 2004 30 USS Hopper “Dare and Do” Guest on David Letterman 16 January 2004 CS 200 Spring 2004 31 Code written by humans Compiler translates from code in a highlevel language to machine code Compiler Code machine can run DrScheme uses an interpreter. An interpreter is like a compiler, except it runs quickly and quietly on small bits of code at a time. 16 January 2004 CS 200 Spring 2004 32 John Backus • Chemistry major at UVA (entered 1943) • Flunked out after second semester • Joined IBM as programmer in 1950 • Developed Fortran, first commercially successful programming language and compiler 16 January 2004 CS 200 Spring 2004 I flunked out every year. I never studied. I hated studying. I was just goofing around. It had the delightful consequence that every year I went to summer school in New Hampshire where I spent the summer sailing and having a nice time. 33 IBM 704 Fortran manual, 1956 “I think there is a world market for maybe five computers.” Thomas Watson, Chairman of IBM, 1943 16 January 2004 CS 200 Spring 2004 34 Backus Naur Form • Fortran language was described using English – Imprecise – Verbose, lots to read – Ad hoc DO 10 I=1.10 Assigns 1.10 to the variable DO10I DO 10 I=1,10 Loops for I = 1 to 10 Often blamed for loss of Mariner-I, but probably not true. • Wanted a more precise way of describing a language 16 January 2004 CS 200 Spring 2004 35 Backus Naur Form non-terminal ::= replacement We can replace non-terminal with replacement A ::= B means anywhere you have an A, you can replace it with a B. Some replacements are terminals: a terminal is something that never appears on the left side of a rule. 16 January 2004 CS 200 Spring 2004 36 BNF Example Sentence ::= NP Verb NP ::= Noun Noun ::= Dave Noun ::= Scheme Verb ::= rocks Verb ::= sucks What are the terminals? Dave, Scheme, rocks, sucks How many different things can we express with this language? 4, but only 2 are true. 16 January 2004 CS 200 Spring 2004 37 BNF Example Sentence ::= NP Verb NP ::= Noun NP ::= Noun and NP Noun ::= Dave Noun ::= Scheme Verb ::= rocks Verb ::= sucks 16 January 2004 CS 200 Spring 2004 How many different things can we express with this language? Infinitely many! Recursion is powerful. 38 Essential Scheme Expression ::= (Expression1 Expression*) Expression ::= (if Expression1 Expression2 Expression3 ) Expression ::= (define name Expression) Expression ::= Primitive Primitive ::= number Primitive ::= + | - | * | / | < | >| = Primitive ::= … (many other primitives) 16 January 2004 CS 200 Spring 2004 39 Problem Set 1 • Due Wednesday (21 Jan) • You are assigned a partner on today’s notes – Unless I didn’t get a registration survey from you (come up after class) • First staffed lab hours will be after class today 16 January 2004 CS 200 Spring 2004 40 Charge • Problem Set 1: Due Wednesday – Staffed lab hours right now! – Take advantage of them • No class Monday: Martin Luther King Day Use the time to learn about history of desegregation at UVa and Dr. King’s visit to UVa in 1963. 16 January 2004 CS 200 Spring 2004 41