The Beauty and Joy of Computing Lecture #4 Functions

Slides:



Advertisements
Similar presentations
CS10 The Beauty and Joy of Computing Lecture #7 Algorithmic Complexity One million Wi-Fi devices isn’t cool. You know what’s cool? A Billion.
Advertisements

CS10 The Beauty and Joy of Computing Lecture #5 : Programming Paradigms Intel has shown demos of the game Wolfenstein whose visual images weren’t.
CS10 The Beauty and Joy of Computing Lecture #5 : Programming Paradigms Times like these make us all appreciate the value of freedom… China.
CS10 The Beauty and Joy of Computing Lecture #25 : Tree Recursion The newly released (and much- hyped) Microsoft Kinect system for the XBOX.
Chapter 2 Writing Simple Programs
Selection. Computer Programming 2 Objectives Examine if statement in more detail Study use of switch statement to implement multialternative selections.
CS39N The Beauty and Joy of Computing Lecture #6 : Programming Paradigms In response to a 30,000+ signature petition, British PM Gordon Brown.
Grammars and Parsing. Sentence  Noun Verb Noun Noun  boys Noun  girls Noun  dogs Verb  like Verb  see Grammars Grammar: set of rules for generating.
CSC 1701B Computing: Science and Creativity. Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings.
Introduction to Python
The Beauty and Joy of Computing Lecture #5 Programming Paradigms Story details the move to Digital of many things precious to us – music, photos, videos.
Prof. Aiken CS 169 Lecture 61 Project Planning CS169 Lecture 6.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
The role of data mining in the last presidential election. A mind-blowing piece on how the Obama campaign used various sources of data to target voters.
The Beauty and Joy of Computing Lecture #5 Programming Paradigms UC Berkeley EECS Sr Lecturer SOE Dan Garcia invent.citris-uc.org motherboard.vice.com/read/click-print-gun-the-inside-story-of-the-3d-printed-gun-movement-video.
Scratch Programming Lesson 4 Question asking and answering.
The Beauty and Joy of Computing Lecture #6 Algorithms MIT researchers recently created an algorithm which they say will be able to predict what topics.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Math – What is a Function? 1. 2 input output function.
The Beauty and Joy of Computing Lecture #6 Algorithms I UC Berkeley EECS Sr Lecturer SOE Dan Garcia.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
The Beauty and Joy of Computing Lecture #5 Programming Paradigms invent.citris-uc.org
The Beauty and Joy of Computing Lecture #7 Algorithms II minors-delete-activity/story?id= /
The Beauty and Joy of Computing Lecture #12 Social Implications of Computing I Online education now has a player in the open access / free education space,
The Beauty and Joy of Computing Lecture #7 Algorithmic Complexity “Data scientists at Yahoo are using prediction markets – along with polls, sentiment.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
CS 104 – Fall 2011 Exploring Computer Science Build Your Own Blocks September 19, 2011.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
UC Berkeley EECS Lecturer SOE Dan Garcia The success of Apple’s Siri (only available on the iPhone 4S) has sparked competition, to be sure. Google’s IRIS.
CS10 The Beauty and Joy of Computing Lecture #4 : Functions UC Berkeley EECS Lecturer SOE Dan Garcia Researchers at Microsoft and UW are working.
CS10 : The Beauty and Joy of Computing Lecture #5 Programming Paradigms If you visited google.com on Saturday, you saw a tribute to this founding.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia Valve (video game makers of Half-Life) believes the future of video games may not be in the input device (ala.
A computer consists of five functionally independent main parts.
Mercer Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
1 Chapter 1: Basic Concepts Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine 9/6/2003.
Functional Programming
CS314 – Section 5 Recitation 9
Chapter 2 Writing Simple Programs
Bill Tucker Austin Community College COSC 1315
Definition of the Programming Language CPRL
Week 2 - Wednesday CS 121.
Grammars and Parsing.
Yahoo predicts contest already!
Chapter No. : 1 Introduction to Java.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia
Topic: Python’s building blocks -> Variables, Values, and Types
Programming the Web Using Visual Studio .NET
Modified from Sharon Guffy
Algorithm Analysis CSE 2011 Winter September 2018.
The Beauty and Joy of Computing Lecture #10 Recursion II
Introduction to the C Language
Learning to Program in Python
Unit I Flash Cards Start.
Objective of This Course
ADTs, Grammars, Parsing, Tree traversals
PHP.
Intro to Algorithms in SNAP!
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
“Under the hood”: Angry Birds Maze
CSCI N207 Data Analysis Using Spreadsheet
Relations And Functions © 2002 by Shawna Haider.
Relations And Functions.
This Lecture Substitution model
Internal components of a computer.
COMPUTING.
Coming up Variables Quick look at scope Primitives Objects
Lecture 6 - Recursion.
Presentation transcript:

The Beauty and Joy of Computing Lecture #4 Functions UC Berkeley EECS Sr Lecturer SOE Dan Garcia Siri competition? evi The success of Apple’s Siri (only available on the iPhone 4S) has sparked competition, to be sure. Google’s IRIS (Siri spelled backward), and now Evi (available on BOTH iOS and Android). The popularity has meant the servers are down (they didn’t use Cloud storage clearly – we’ll learn about that later). Love where this is going! www.technologyreview.com/computing/39560/

Generalization (in CS10) REVIEW You are going to learn to write functions, like in math class: y = sin(x) sin is the function x is the input It returns a single value, a number x sin “Function machine” from Simply Scheme (Harvey)

CS Illustrated function metaphor Function basics Functions take in 0 or more inputs and return exactly 1 output The same inputs MUST yield same outputs. Output function of input only Other rules of functions No state (prior history) No mutation (no variables get modified) No side effects (nothing else happens) CS Illustrated function metaphor

More Terminology (from Math) Domain The “class” of input a function accepts Examples Sqrt of Positive numbers Length of Sentence, word, number _ < _ Both: Sentence, word, number _ and _ Booleans Letter _ of _ Number from 1 to input length Range All the possible return values of a function Examples Sqrt of Non-negative numbers Length of Non-negative integer _ < _ Boolean (true or false) _ and _ Letter _ of _ Letter

Types of input (there are more) Sentences Word Character Digit Words separated by N spaces, N ≥ 0 E.g., CS 10 is great Length ≥ 1, no spaces Cal, 42, CS10 Length = 1 E.g., A, 3, # 0-9 only E.g., 7

Why functions are great! If a function only depends on the information it gets as input, then nothing else can affect the output. It can run on any computer and get the same answer. This makes it incredibly easy to parallelize functions. Functional programming is a great model for writing software that runs on multiple systems at the same time. Datacenter

Scratch  BYOB (Build Your Own Blocks) Invented @ MIT Maintained by MIT Huge community Sharing via Website No functions  Scratch 2.0 in Flash No iOS devices.  scratch.mit.edu BYOB (to be “SNAP!”) Based on Scratch code Maintained by jens & Cal Growing community No sharing (yet)  Functions!  … “Blocks” BYOB 4.0 in HTML5 All devices  byob.berkeley.edu

The power of generalization! Why use functions? (1) The power of generalization!

Why use functions? (2) They can be composed together to make even more magnificent things. They are literally the building blocks of almost everything that we create when we program. We call the process of breaking big problems down into smaller tasks functional decomposition

Types of Blocks Command Reporter (Function) Predicate (Function) No outputs, meant for side-effects Reporter (Function) Any type of output Predicate (Function) Boolean output (true or false)

Quick Preview: Recursion Recursion is a technique for defining functions that use themselves to complete their own definition. We will spend a lot of time on this. M. C. Escher : Drawing Hands

Functional Programming Summary en.wikipedia.org/wiki/Functional_programming Functional Programming Summary Computation is the evaluation of functions Plugging pipes together Each pipe, or function, has exactly 1 output Functions can be input! Features No state E.g., variable assignments No mutation E.g., changing variable values No side effects Need BYOB not Scratch f(x)=(x+3)* x x x 3 x + f *