David Evans CS200: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!

Slides:



Advertisements
Similar presentations
Class 3: Rules of Evaluation David Evans cs1120 Fall 2009.
Advertisements

ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
CS107: Introduction to Computer Science Lecture 2 Jan 29th.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Exponential Functions Logarithmic Functions
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
Summer 2011 Wednesday, 07/13. Formal Systems: The ELI System The ELI-system uses only three letters of the alphabet: E, L, I. It has a single axiom, EI,
PRE - ALGEBRA.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein
II–2 DC Circuits I Theory & Examples.
Discrete Mathematics Recursion and Sequences
30-Jun-15 BNF. Metalanguages A metalanguage is a language used to talk about a language (usually a different one) We can use English as its own metalanguage.
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
Introduction to the Adjective/Noun Theme. © 2012 Math As A Second Language All Rights Reserved next #1 Taking the Fear out of Math.
Please open your laptops, log in to the MyMathLab course web site, and open Quiz 4.1/4.2. IMPORTANT NOTE: If you have time left after you finish this quiz,
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
Grammars and Parsing. Sentence  Noun Verb Noun Noun  boys Noun  girls Noun  dogs Verb  like Verb  see Grammars Grammar: set of rules for generating.
Theory Of Automata By Dr. MM Alam
Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.
计算机科学概述 Introduction to Computer Science 陆嘉恒 中国人民大学 信息学院
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 2: Orders of Growth
计算机科学概述 Introduction to Computer Science 陆嘉恒 中国人民大学 信息学院
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Skill Area 311 Part A. Lecture Overview Binary Numbers Binary Arithmetic ASCII Code Machine Code Instruction Format Advantages and disadvantages of machine.
An Overview of Programming in Python CSC 161: The Art of Programming Prof. Henry Kautz 9/9/2009 Slides stolen shamelessly from Dr. Mark Goadrich, Centenary.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
How Computers Work … and how you can work them. Art 315 Lecture 03 Dr. J Parker Fall 2010.
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
David Evans CS200: Computer Science University of Virginia Computer Science Class 25: Computability Halting Problems Hockey.
Introduction to Programming with RAPTOR
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
Game Maker – Getting Started What is Game Maker?.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 3: Levels of Abstraction
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!
Lecture 2: Formal Systems and Languages MU! CS150: Computer Science
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Adding and Subtracting Decimals © Math As A Second Language All Rights Reserved next #8 Taking the Fear out of Math 8.25 – 3.5.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
Lecture 3: Rules of Evaluation CS150: Computer Science
1 CS100J Spring Instructor: David Gries CS100M: Matlab No prior programming experience One semester of calculus Math & engineering type problems.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
(Thunking about Thunks)
CMSC201 Computer Science I for Majors Lecture 02 – Algorithmic Thinking Prof. Katherine Gibson Based on slides by Shawn Lupoli and Max Morawski at UMBC.
Lecture 6: Lambda Calculus
Lecture 2: Schreme David Evans
Lecture 4: Evaluation Rules Recursion CS200: Computer Science
Class 27: Universal Turing Machines CS150: Computer Science
Lecture 37: A Universal Computer
Lambda Calculus Revisited
Chapter 10 Programming Fundamentals with JavaScript
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Lecture 2: Formal Systems and Languages MU! CS200: Computer Science
SSEA Computer Science: Track A
Tonga Institute of Higher Education IT 141: Information Systems
Class 31: Universal Turing Machines CS200: Computer Science
Class 34: Models of Computation CS200: Computer Science
Tonga Institute of Higher Education IT 141: Information Systems
Lecture 3: Rules of Evaluation CS200: Computer Science
Discrete Maths 13. Grammars Objectives
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

David Evans CS200: Computer Science University of Virginia Computer Science Lecture 2: Formal Systems and Languages MU!

17 January 2003CS 200 Spring Menu Questions from Lecture 1 Notes Formal Systems –MIU-system Languages –English –Scheme Pictures

17 January 2003CS 200 Spring 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 2006 to compute the same photomosaic? How long will it take in 2009? > (/ (* ( ) 12) 18)) 2 > (/ 60 (* 2 2)) 15 > (/ (* ( ) 12) 18) 4 > (/ 60 (* )) 15/4 > (exact->inexact (/ 60 (* ))) 3.75 Difference in years * 12 = number of months Number of months / 18 = number of doublings according to Moore’s Law 60 seconds today, 2 doublings by seconds in seconds today, 4 doublings by seconds in 2009

17 January 2003CS 200 Spring 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 non- recursive “languages” (some linguists argue they are not really “languages”), but only humans can learn recursive languages.

17 January 2003CS 200 Spring 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!

17 January 2003CS 200 Spring Survey Results Summary of your answers to the other questions and my answers to the your questions are on the course web site.

17 January 2003CS 200 Spring Class Overview 14 Different Majors Cognitive Science (11), Undecided (6), Pre-Commerce (3), Cognitive Science prospective (2), Computer Science (2), Electrical Engineering (2), Computer Engineering, Economics, French, Neuroscience (prospective), Math, Mechanical Engineering, Music, Physics, Russian Studies, Systems Engineering Experience –Never written a computer program: 14 –Took at least one CS course: 7

17 January 2003CS 200 Spring Formal Systems

17 January 2003CS 200 Spring 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

17 January 2003CS 200 Spring 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 M x. Then you may add M xx 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.

17 January 2003CS 200 Spring 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 M x. Then you may add M xx 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.

17 January 2003CS 200 Spring Languages

17 January 2003CS 200 Spring 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.

17 January 2003CS 200 Spring Linguist’s Definition 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. (Charles Yang)

17 January 2003CS 200 Spring Languages and Formal Systems What is the difference between a formal system and a language? With a language, the surface forms have meaning.

17 January 2003CS 200 Spring 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

17 January 2003CS 200 Spring 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

17 January 2003CS 200 Spring 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.

17 January 2003CS 200 Spring Detour: History of Computer Programming How should we describe languages?

17 January 2003CS 200 Spring 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 Apollo Guidance Computer (1969): 1 inch You: 1.6 miles ENIAC (1946): ½ mm

17 January 2003CS 200 Spring 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.

17 January 2003CS 200 Spring 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) Admiral Grace Hopper ( ) “Nobody believed that I had a running compiler and nobody would touch it. They told me computers could only do arithmetic.”

17 January 2003CS 200 Spring USS Hopper Guest on David Letterman “Dare and Do”

17 January 2003CS 200 Spring Code written by humans Compiler Code machine can run Compiler translates from code in a high- level language to machine code DrScheme uses an interpreter. An interpreter is like a compiler, except it runs quickly and quietly on small bits of code at a time.

17 January 2003CS 200 Spring 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 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.

17 January 2003CS 200 Spring IBM 704 Fortran manual, 1956 “I think there is a world market for maybe five computers.” Thomas Watson, Chairman of IBM, 1943

17 January 2003CS 200 Spring 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

17 January 2003CS 200 Spring Backus Naur Form non-terminal ::= replacement We can replace non-terminal with replacement Some replacements are terminals: a terminal is something that never appears on the left side of a rule. A ::= B means anywhere you have an A, you can replace it with a B.

17 January 2003CS 200 Spring BNF Example Sentence ::= NP Verb NP ::= Noun Noun ::= Dave Noun ::= Scheme Verb ::= rocks Verb ::= sucks How many different things can we express with this language? What are the terminals? Dave, Scheme, rocks, sucks 4, but only 2 are useful.

17 January 2003CS 200 Spring BNF Example Sentence ::= NP Verb NP ::= Noun NP ::= Noun and NP Noun ::= Dave Noun ::= Scheme Verb ::= rocks Verb ::= sucks How many different things can we express with this language? Infinitely many! Recursion is powerful.

17 January 2003CS 200 Spring Scheme

17 January 2003CS 200 Spring Scheme Like all powerful languages, Scheme has: – Primitives – Means of Combination – Means of Abstraction

17 January 2003CS 200 Spring Scheme Primitives Examples Numbers Functions + -round Constants #f#t (false) (true) The primitives probably mean what you think they do (but expressing precisely what they mean is hard).

17 January 2003CS 200 Spring Means of Combination Application Expression ::= (Expression) Expression ::= (Expression Expression) Expression ::= (Expression Expression Expression)... Expression ::= (Expression Expression*) ( ) (* (+ 0 (+ 2 2)) 6) “Evaluate all the expressions, then apply the first expression (a procedure) to all the other values.”

17 January 2003CS 200 Spring Means of Combination Special Forms (if Expression 1 Expression 2 Expression 3 ) If the value of Expression 1 is #f, the value of the if is the value of Expression 3. Otherwise, it is the value of Expression 2. A few others we’ll see later…

17 January 2003CS 200 Spring Means of Abstraction Expression ::= (define name Expression) > (define two 2) > (define plus +) > (plus two two) 4 > (define five 4) > (= (plus two two) five) #t Note that define s don’t evaluate to anything.

17 January 2003CS 200 Spring Essential Scheme Expression ::= ( Expression 1 Expression* ) Expression ::= (if Expression 1 Expression 2 Expression 3 ) Expression ::= (define name Expression ) Expression ::= Primitive Primitive ::= number Primitive ::= + | - | * | / | | = Primitive ::= …(many other primitives)

17 January 2003CS 200 Spring Why do we program computers using Scheme (or some other programming languages) instead of English? Think about for next class…

17 January 2003CS 200 Spring The first bug: Moth found in UNIVAC relay Admiral Hopper’s Notebook, Sept 1945 Precise language means interpreter will do exactly what you express (following the rules we learn next class), and nothing else.

17 January 2003CS 200 Spring Charge Problem Set 1: Due Wednesday –Staffed lab hours right now! (and 2pm Saturday, 1pm Sunday) –Take advantage of them No class Monday: Martin Luther King Day Use the time to learn about: Segregation at UVa, Dr. King’s visit to UVa in 1963, student led protests in 1969 Remember to take pictures!