2.2 Data Abstraction
|
|
- Gavin Malone
- 5 years ago
- Views:
Transcription
1 ITP Programming Languages Chapter 2 Building Abstractions with Data 2.1 Introduction Functional Abstraction vs. Data Abstraction 2.2 Data Abstraction Example: Rational Numbers Major references: 1. Structure and Interpretation of Computer Programs(SICP) by Abelson and Sussman, MIT Composing Programs by John DeNero, Google 2. MITx OPENCOURSEWARE(OCW) 6.00 SC Lecture 3. UC Berkley CS61A Lecture 4. Python, Wikipedia and many on-line resources. Prof. Youngsup Kim, idebtor@handong.edu, 2014 Programming Languages, CSEE Dept., Handong Global University
2 Function 2
3 Functional Abstraction: 3
4 Functional Abstraction: using primitive data and operations 4
5 Functional Abstraction: using primitive data and operations forming functions through composition and control 5
6 Functional Abstraction: using primitive data and operations forming functions through composition and control giving names to processes 6
7 Functional Abstraction: using primitive data and operations forming functions through composition and control giving names to processes using higher-order functions 7
8 Functional Abstraction: using primitive data and operations forming functions through composition and control giving names to processes using higher-order functions These abstractions enhance the power of our programming language that is much of the essence of programming Functional Abstraction 8
9 Functional Abstraction: using primitive data and operations forming functions through composition and control giving names to processes using higher-order functions These abstractions enhance the power of our programming language that is much of the essence of programming Functional Abstraction Data Abstraction 9
10 Data 10
11 2. What is Data? Data 11
12 2. What is Data? Data: the things that programs fiddle with 12
13 2. What is Data? Data: the things that programs fiddle with Primitive values are the simplest type of data Integers: 2, 3, 2013, Floating point (decimal) values: 4.5, 98.6 Booleans: True, False 13
14 2. What is Data? Data: the things that programs fiddle with Primitive values are the simplest type of data Integers: 2, 3, 2013, Floating point (decimal) values: 4.5, 98.6 Booleans: True, False How do we represent more complex data? 14
15 2. What is Data? Data: the things that programs fiddle with Primitive values are the simplest type of data Integers: 2, 3, 2013, Floating point (decimal) values: 4.5, 98.6 Booleans: True, False How do we represent more complex data? Example: 15
16 2. What is Data? Data: the things that programs fiddle with Primitive values are the simplest type of data Integers: 2, 3, 2013, Floating point (decimal) values: 4.5, 98.6 Booleans: True, False How do we represent more complex data? Example: Creation Sin Sacrifice Sky 16
17 2. What is Data? Data: the things that programs fiddle with Primitive values are the simplest type of data Integers: 2, 3, 2013, Floating point (decimal) values: 4.5, 98.6 Booleans: True, False How do we represent more complex data? Example: Creation Sin Sacrifice Sky We need data abstraction! 17
18 2. Data Abstraction 18
19 2. Data Abstraction Compound Data combines smaller pieces of data together. A date: a year, month, and day A coordinate: x, y, z 19
20 2. Data Abstraction Compound Data combines smaller pieces of data together. A date: a year, month, and day A coordinate: x, y, z An abstract data type(adt) lets us manipulate compound data as a unit. This isolates any program that deals with into two parts: - How data are represented (as parts) - How data are manipulated (as units) This is the data abstraction - a powerful design methodology. 20
21 2. Data Abstraction Compound Data combines smaller pieces of data together. A date: a year, month, and day A coordinate: x, y, z All Programs, All Programmers An abstract data type(adt) lets us manipulate compound data as a unit. This isolates any program that deals with into two parts: - How data are represented (as parts) - How data are manipulated (as units) This is the data abstraction - a powerful design methodology. 21
22 2. Data Abstraction Compound Data combines smaller pieces of data together. A date: a year, month, and day A coordinate: x, y, z All Programs, All Programmers Great Programs, Great Programmers! An abstract data type(adt) lets us manipulate compound data as a unit. This isolates any program that deals with into two parts: - How data are represented (as parts) - How data are manipulated (as units) This is the data abstraction - a powerful design methodology. 22
23 2. Data Abstraction A methodology by which functions enforce an abstraction barrier between representation and use. 23
24 2. Data Abstraction A methodology by which functions enforce an abstraction barrier between representation and use. makes programs much easier to design, maintain, and modify. isolates how a compound data value is used from the details of how it is constructed. 24
25 2.2 Example: Rational Number see Rational Numbers: 25
26 2.2 Example: Rational Number see Rational Numbers: numerator denominator 26
27 2.2 Example: Rational Number see Rational Numbers: numerator denominator Exact representation of fractions A pair of integers As soon as division occurs, the exact representation is lost! Assume we can compose and decompose rational numbers: 27
28 2.2 Example: Rational Number see Rational Numbers: numerator denominator Exact representation of fractions A pair of integers As soon as division occurs, the exact representation is lost! Assume we can compose and decompose rational numbers: rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 28
29 2.2 Example: Rational Number see Rational Numbers: numerator denominator Exact representation of fractions A pair of integers As soon as division occurs, the exact representation is lost! Assume we can compose and decompose rational numbers: Constructor Selectors rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 29
30 2.2 Example: Rational Number see To facilitate data abstraction, we create two types of functions: Constructors are functions that build the abstract data type. Selectors are functions that retrieve information from the data type Constructor Selectors rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 30
31 2.2 Example: Rational Number Arithmetic Example: General Form: = 9 10 nx dx ny dy = nx ny dx dy = nx dx + ny dy = nx ny + ny dx dx dy 31
32 2.2 Example: Rational Number Arithmetic Example: General Form: = 9 10 nx dx ny dy = nx ny dx dy = nx dx + ny dy = nx ny + ny dx dx dy 32
33 2.2 Example: Rational Number Code 33
34 2.2 Example: Rational Number Code rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 34
35 2.2 Example: Rational Number Code Wishful thinking rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 35
36 2.2 Example: Rational Number Code Wishful thinking: a powerful strategy for designing programs. The following three functions have not defined yet; even so, if we define them, we could then add, multiply, and test equality of rational numbers. Wishful thinking rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 36
37 2.2 Example: Rational Number Code def mul_rationals(x, y): return rational(numer(x) * numer(y), denom(x) * denom(y)) Constructor Wishful thinking rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 37
38 2.2 Example: Rational Number Code def mul_rationals(x, y): return rational(numer(x) * numer(y), denom(x) * denom(y)) Constructor Selector Wishful thinking rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 38
39 2.2 Example: Rational Number Code def mul_rationals(x, y): return rational(numer(x) * numer(y), denom(x) * denom(y)) def add_rationals(x, y): nx, dx = numer(x), denom(x) ny, dy = numer(y), denom(y) return rational(nx * dy + ny * dx, dx * dy) Wishful thinking rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 39
40 2.2 Example: Rational Number Code def print_rational(r): print (numer(r), '/', denom(r)) def eq_rationals(x, y): return numer(x) * denom(y) == numer(y) * denom(x) Wishful thinking rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 40
41 2.2 Example: Rational Number Code Wishful thinking: a powerful strategy for designing programs. Now, let s think about these three functions: Wishful thinking rational(n, d) returns a rational number x. numer(x) returns the numerator of x. denom(x) returns the denominator of x. 41
42 pair 42
43 Representing Pairs Using Lists >>> pair = [1, 2] >>> pair [1, 2] >>> x, y = pair >>> x 1 >>> y 2 >>> pair[0] 1 >>> pair[1] 2 >>> from operator import getitem >>> getitem(pair, 0) 1 >>> getitem(pair, 1) 2 A list literal: Comma-separated expressions in brackets "Unpacking" a list Element selection using the selection operator Element selection function tuple( ): fixed-length, immutable sequence Stay tuned for more tuple and list later 43
44 2.2 Example: Representing Rational Number rational(n, d): It is a pair of integer. 44
45 2.2 Example: Representing Rational Number def rational(n, d): It is a pair of integer. """Construct a rational number x that represents n/d.""" return [n, d] 45
46 2.2 Example: Representing Rational Number def rational(n, d): """Construct a rational number x that represents n/d.""" return [n, d] 46
47 2.2 Example: Representing Rational Number def rational(n, d): """Construct a rational number x that represents n/d.""" return [n, d] Construct a list 47
48 2.2 Example: Representing Rational Number def rational(n, d): """Construct a rational number x that represents n/d.""" return [n, d] Construct a list from operator import getitem def numer(x): """Return the numerator of rational number x.""" return getitem(x, 0) # return x[0] def denom(x): """Return the denominator of rational number x.""" return getitem(x, 1) # return x[1] Select from a list 48
49 2.2 Example: Rational Number Demo Demo: >>> half = rational(1, 2) >>> third = rational(1, 3) >>> print_rational(half) 1 / 2 >>> print_rational(third) 1 / 3 >>> print_rational(mul_rationals(half, third)) 1 / 6 >>> print_rational(add_rationals(half, thrid)) 5 / 6 Work or not? >>> >>> print_rational(add_rationals( [1,2], [1,4] )) 6 / 8 >>> print_rational(mul_rationals( (1,2), (1,4) )) 1 / 8 >>> 49
50 2.2 Example: Rational Number Challenge: reducing the rational numbers to lowest terms Example: = = /3 1/3 = /25 1/25 =
51 2.2 Example: Rational Number Challenge: reducing the rational numbers to lowest terms Example: = = /3 1/3 = /25 1/25 = 1 2 from fractions import gcd def rational(n, d): """Construct a rational number x that represents n/d.""" g = gcd(n, d) return [n//g, d//g] 51
52 2.2 Example: Rational Number Challenge: reducing the rational numbers to lowest terms Example: = = /3 1/3 = /25 1/25 = 1 2 Greatest common divisor from fractions import gcd def rational(n, d): """Construct a rational number x that represents n/d.""" g = gcd(n, d) return [n//g, d//g] 52
53 2.2 Data Abstraction: Abstraction Barriers see
54 2.2 Data Abstraction: Abstraction Barriers see Rational numbers as whole data values add_rationals mul_rationals eq_rationals print_rational Rational numbers as numerators & denominators rational numer denom Rational numbers as lists (or tuples) list getitem However list or tuple is implemented in Python. 54
55 2.2 Data Abstraction: Abstraction Barriers see Example: Breaking Abstraction Barriers Does not use constructors add_rationals( [1, cvcv 2], [1, 4] ) 55
56 2.2 Data Abstraction: Abstraction Barriers Example: Breaking Abstraction Barriers Does not use constructors Twice! add_rationals( [1, cvcv 2], [1, cvcv 4] ) 56
57 2.2 Data Abstraction: Abstraction Barriers Example: Breaking Abstraction Barriers Does not use constructors Twice! add_rationals( [1, cvcv 2], [1, cvcv 4] ) def divide_rationals(x, y): return (x[0] * y[1], x[1] * y[0]) 57
58 2.2 Data Abstraction: Abstraction Barriers Example: Breaking Abstraction Barriers Does not use constructors Twice! add_rationals( [1, cvcv 2], [1, cvcv 4] ) def divide_rationals(x, y): return (x[0] * y[1], x[1] * y[0]) cvcv No selectors! 58
59 2.2 Data Abstraction: Abstraction Barriers Example: Breaking Abstraction Barriers Does not use constructors Twice! add_rationals( [1, cvcv2], [1, cvcv4] ) def divide_rationals(x, y): return (x[0] * y[1], x[1] * y[0]) cvcv No selectors! cvcv And no constructor! 59
60 2.2 Data Abstraction: Abstraction Barriers see Example: Breaking Abstraction Barriers Does not use constructors Twice! add_rationals( [1, cvcv 2], [1, cvcv 4] ) def divide_rationals(x, y): return (x[0] * y[1], x[1] * y[0]) cvcv No selectors! cvcv And no constructor! These implementations would require rewriting whenever the implementation of rational number functions changed. 60
61 2.2 Example: Rational Number Demo Demo: >>> half = rational(1, 2) >>> third = rational(1, 3) >>> print_rational(half) 1 / 2 >>> print_rational(third) 1 / 3 >>> print_rational(mul_rationals(half, third)) 1 / 6 >>> print_rational(add_rationals(half, thrid)) 5 / 6 Work or not? >>> >>> print_rational(add_rationals( [1,2], [1,4] )) 6 / 8 >>> print_rational(mul_rationals( (1,2), (1,4) )) 1 / 8 >>> 61
62 2.2 Example: Rational Number Demo Demo: >>> half = rational(1, 2) >>> third = rational(1, 3) >>> print_rational(half) 1 / 2 >>> print_rational(third) 1 / 3 >>> print_rational(mul_rationals(half, third)) 1 / 6 >>> print_rational(add_rationals(half, thrid)) 5 / 6 Work or not? >>> >>> print_rational(add_rationals( [1,2], [1,4] )) 6 / 8 >>> print_rational(mul_rationals( (1,2), (1,4) )) 1 / 8 >>> It worked, but broke abstraction barriers. 62
63 2.2 What is an Abstract Data Type? We need to guarantee that constructor and selector functions together specify the right behavior. Behavior condition: If we construct rational number x from numerator n and denominator d, then numer(x)/denom(x) must equal n/d. An abstract data type is a collection of constructors and selector and, together with some behavior conditions. If behavior conditions are met, the representation is valid. You can recognize data types by behavior, not by bits. 63
64 2.2 Behavior Conditions of a Pair see To implement our rational number abstract data type, we used a two element list (called as a pair, here). What is a pair? Constructors, selectors, and behavior conditions: If a pair p was constructed from elements x and y, then select(p, 0) returns x, and select(p, 1) returns y. Together, selectors are the inverse of the constructor. Generally true of container types. Not true for rational numbers because of GCD 64
65 2.2 Functional Pairs Implementation see 2.2.2~4 We don t need to use the Python list or tuple type if we can implement two functions pair and select that fulfills behavior conditions of a pair. 65
66 2.2 Functional Pairs Implementation see 2.2.2~4 We don t need to use the Python list or tuple type if we can implement two functions pair and select that fulfills behavior conditions of a pair. def pair(x, y): """Return a functional pair.""" def get(m): if m == 0: cvcv return x elif m == 1: return y return get This function represents a pair. not using list. Constructor is a higher-order function 66
67 2.2 Functional Pairs Implementation see 2.2.2~4 We don t need to use the Python list or tuple type if we can implement two functions pair and select that fulfills behavior conditions of a pair. def pair(x, y): """Return a functional pair.""" def get(m): if m == 0: cvcv return x elif m == 1: return y return get This function represents a pair. Constructor is a higher-order function def select(p, i): """Return the element at index i of pair p.""" return p(i) 67
68 2.2 Functional Pairs Implementation see 2.2.2~4 We don t need to use the Python list or tuple type if we can implement two functions pair and select that fulfills behavior conditions of a pair. def pair(x, y): """Return a functional pair.""" def get(m): if m == 0: cvcv return x elif m == 1: return y return get This function represents a pair. Constructor is a higher-order function def select(p, i): """Return the element at index i of pair p.""" return p(i) cvcv Selector defers to the functional pair. 68
69 2.2 Functional Pairs Implementation see 2.2.2~4 Demo: >>> p = pair(1, 2) >>> select(p, 0) 1 >>> select(p, 1) 2 69
70 2.2 Functional Pairs Implementation see 2.2.2~4 Demo: >>> p = pair(1, 2) >>> select(p, 0) 1 As long as we do not violate the abstraction barrier, we don't need to know that pairs are just simple functions. >>> select(p, 1) 2 70
71 2.2 Functional Pairs Implementation see 2.2.2~4 Demo: >>> p = pair(1, 2) >>> select(p, 0) 1 As long as we do not violate the abstraction barrier, we don't need to know that pairs are just simple functions. >>> select(p, 1) 2 If a pair p was constructed from elements x and y, then select(p, 0) returns x, and select(p, 1) returns y. 71
72 2.2 Functional Pairs Implementation see 2.2.2~4 Demo: >>> p = pair(1, 2) >>> select(p, 0) 1 As long as we do not violate the abstraction barrier, we don't need to know that pairs are just simple functions. >>> select(p, 1) 2 If a pair p was constructed from elements x and y, then select(p, 0) returns x, and select(p, 1) returns y. Therefore, this pair representation is valid! 72
61A LECTURE 7 DATA ABSTRACTION. Steven Tang and Eric Tzeng July 3, 2013
61A LECTURE 7 DATA ABSTRACTION Steven Tang and Eric Tzeng July 3, 2013 Announcements Trends project released later today. Due in ~2 weeks Extra midterm office hours Sunday, from noon to 6pm in 310 Soda
More informationPython List built-in methods, accessing elements, selection, slicing, recursive functions, list comprehension
ITP 20005 Programming Languages Chapter 2 Building Abstractions with Data 2.1 Introduction 2.2 Data Abstraction 2.3 Sequences List, Tuple, String, Linked List Major references: 1. Structure and Interpretation
More informationITP Programming Languages Chapter 2 Building Abstractions with Data 2.5 Object-Oriented Programming 1. Polymorphism repr, str Interface
ITP 20005 Programming Languages Chapter 2 Building Abstractions with Data 2.5 Object-Oriented Programming 1. Polymorphism repr, str 2. Interface 3. @property 4. Example Complex number Major references:
More informationDATA ABSTRACTION 5. February 21, 2013
DATA ABSTRACTION 5 COMPUTER SCIENCE 61A February 21, 2013 1 Data Abstraction Data abstraction is a powerful concept in computer science that allows programmers to treat code as objects for example, car
More informationStructure and Interpretation of Computer Programs Fall 2012 Alternate Midterm 1
CS 6A Structure and Interpretation of Computer Programs Fall 0 Alternate Midterm INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,
More informationDATA ABSTRACTION 4. September 25, 2014
DATA ABSTRACTION 4 COMPUTER SCIENCE 61A September 25, 2014 1 Data Abstraction Data abstraction is a powerful concept in computer science that allows programmers to treat code as objects for example, car
More informationChapter 2: Building Abstractions with Data
Chapter 2: Building Abstractions with Data Contents 2.1 Introduction 1 2.2 Data Abstraction 1 2.2.1 Example: Arithmetic on Rational Numbers............................. 2 2.2.2 Tuples................................................
More informationChapter 2: Building Abstractions with Objects
Chapter 2: Building Abstractions with Objects Contents 2.1 Introduction 1 2.1.1 The Object Metaphor........................................ 1 2.1.2 Native Data Types..........................................
More information61A LECTURE 8 SEQUENCES, ITERABLES
61A LECTURE 8 SEQUENCES, ITERABLES Steven Tang and Eric Tzeng July 8, 013 Announcements Homework 4 due tonight Homework 5 is out, due Friday Midterm is Thursday, 7pm Thanks for coming to the potluck! What
More information61A LECTURE 8 SEQUENCES, ITERABLES. Steven Tang and Eric Tzeng July 8, 2013
61A LECTURE 8 SEQUENCES, ITERABLES Steven Tang and Eric Tzeng July 8, 2013 Announcements Homework 4 due tonight Homework 5 is out, due Friday Midterm is Thursday, 7pm Thanks for coming to the potluck!
More informationMutation & Data Abstraction Summer 2018 Discussion 4: July 3, Mutable Lists
CS 61A Mutation & Data Abstraction Summer 2018 Discussion 4: July 3, 2018 1 Mutable Lists Let s imagine you order a mushroom and cheese pizza from La Val s, and that they represent your order as a list:
More informationLists, Mutability, ADTs, and Trees Spring 2019 Guerrilla Section 2: March 2, 2019 Solutions. 1 Sequences. Questions. lst = [1, 2, 3, 4, 5] lst[1:3]
CS 61A Lists, Mutability, ADTs, and Trees Spring 2019 Guerrilla Section 2: March 2, 2019 Solutions 1 Sequences Questions 1.1 What would Python display? lst = [1, 2, 3, 4, 5] lst[1:3] [2, 3] lst[0:len(lst)]
More informationUnit: Rational Number Lesson 3.1: What is a Rational Number? Objectives: Students will compare and order rational numbers.
Unit: Rational Number Lesson 3.: What is a Rational Number? Objectives: Students will compare and order rational numbers. (9N3) Procedure: This unit will introduce the concept of rational numbers. This
More informationRational numbers as decimals and as integer fractions
Rational numbers as decimals and as integer fractions Given a rational number expressed as an integer fraction reduced to the lowest terms, the quotient of that fraction will be: an integer, if the denominator
More informationGateway Regional School District VERTICAL ALIGNMENT OF MATHEMATICS STANDARDS Grades 3-6
NUMBER SENSE & OPERATIONS 3.N.1 Exhibit an understanding of the values of the digits in the base ten number system by reading, modeling, writing, comparing, and ordering whole numbers through 9,999. Our
More information(Type your answer in radians. Round to the nearest hundredth as needed.)
1. Find the exact value of the following expression within the interval (Simplify your answer. Type an exact answer, using as needed. Use integers or fractions for any numbers in the expression. Type N
More informationSection 2.3 Rational Numbers. A rational number is a number that may be written in the form a b. for any integer a and any nonzero integer b.
Section 2.3 Rational Numbers A rational number is a number that may be written in the form a b for any integer a and any nonzero integer b. Why is division by zero undefined? For example, we know that
More information6.001 Notes: Section 5.1
6.001 Notes: Section 5.1 Slide 5.1.1 In this lecture we are going to continue with the theme of building abstractions. Thus far, we have focused entirely on procedural abstractions: the idea of capturing
More informationRational number operations can often be simplified by converting mixed numbers to improper fractions Add EXAMPLE:
Rational number operations can often be simplified by converting mixed numbers to improper fractions Add ( 2) EXAMPLE: 2 Multiply 1 Negative fractions can be written with the negative number in the numerator
More information4A: Introduction to Data Abstraction
Low Kok Lim August 31, 2016 Recap: Assessment Overview 35%: Missions 5%: Discussion group participation 15%: Midterm Assessment (28 Sep, Wed, 10am) 15%: Practical Assessment (10 Nov, Thu, 7pm ) 30%: Final
More informationCSc 372 Comparative Programming Languages
CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Christian Collberg collberg+372@gmail.com Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg
More informationCSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona
1/43 CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg Functions over Lists
More informationIntegers are whole numbers; they include negative whole numbers and zero. For example -7, 0, 18 are integers, 1.5 is not.
What is an INTEGER/NONINTEGER? Integers are whole numbers; they include negative whole numbers and zero. For example -7, 0, 18 are integers, 1.5 is not. What is a REAL/IMAGINARY number? A real number is
More informationAdding and subtracting rational expressions is quite similar to adding and subtracting rational numbers (fractions).
7.2: Adding and Subtracting Rational Expressions, Simplifying Complex Fractions Adding and subtracting rational expressions is quite similar to adding and subtracting rational numbers (fractions). Adding
More informationWhat is a Fraction? Fractions. One Way To Remember Numerator = North / 16. Example. What Fraction is Shaded? 9/16/16. Fraction = Part of a Whole
// Fractions Pages What is a Fraction? Fraction Part of a Whole Top Number? Bottom Number? Page Numerator tells how many parts you have Denominator tells how many parts are in the whole Note: the fraction
More informationReteaching. Comparing and Ordering Integers
- Comparing and Ordering Integers The numbers and - are opposites. The numbers 7 and -7 are opposites. Integers are the set of positive whole numbers, their opposites, and zero. 7 6 4 0 negative zero You
More informationLists, Mutability, ADTs, and Trees Spring 2019 Guerrilla Section 2: March 2, Sequences. Questions. lst = [1, 2, 3, 4, 5] lst[1:3]
CS 61A Lists, Mutability, ADTs, and Trees Spring 2019 Guerrilla Section 2: March 2, 2019 1 Sequences 1.1 What would Python display? lst = [1, 2, 3, 4, 5] lst[1:3] lst[0:len(lst)] lst[-4:] lst[:3] lst[3:]
More informationHOW TO DIVIDE: MCC6.NS.2 Fluently divide multi-digit numbers using the standard algorithm. WORD DEFINITION IN YOUR WORDS EXAMPLE
MCC6.NS. Fluently divide multi-digit numbers using the standard algorithm. WORD DEFINITION IN YOUR WORDS EXAMPLE Dividend A number that is divided by another number. Divisor A number by which another number
More informationCreating a new data type
Appendix B Creating a new data type Object-oriented programming languages allow programmers to create new data types that behave much like built-in data types. We will explore this capability by building
More informationCourse Learning Outcomes for Unit I. Reading Assignment. Unit Lesson. UNIT I STUDY GUIDE Number Theory and the Real Number System
UNIT I STUDY GUIDE Number Theory and the Real Number System Course Learning Outcomes for Unit I Upon completion of this unit, students should be able to: 2. Relate number theory, integer computation, and
More informationRational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 10.
PA Ch 5 Rational Expressions Rational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 0. Since decimals are special
More information61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013
61A LECTURE 1 FUNCTIONS, VALUES Steven Tang and Eric Tzeng June 24, 2013 Welcome to CS61A! The Course Staff - Lecturers Steven Tang Graduated L&S CS from Cal Back for a PhD in Education Eric Tzeng Graduated
More informationMath Circle Beginners Group October 18, 2015 Solutions
Math Circle Beginners Group October 18, 2015 Solutions Warm-up problem 1. Let n be a (positive) integer. Prove that if n 2 is odd, then n is also odd. (Hint: Use a proof by contradiction.) Suppose that
More information6.001 Notes: Section 8.1
6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything
More informationGIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes
GIS 4653/5653: Spatial Programming and GIS More Python: Statements, Types, Functions, Modules, Classes Statement Syntax The if-elif-else statement Indentation and and colons are important Parentheses and
More informationCIT 590 Homework 6 Fractions
CIT 590 Homework 6 Fractions Purposes of this assignment: Get you started in Java and Eclipse Get you comfortable using objects in Java Start looking at some common object uses in Java. General Idea of
More information6.1 Evaluate Roots and Rational Exponents
VOCABULARY:. Evaluate Roots and Rational Exponents Radical: We know radicals as square roots. But really, radicals can be used to express any root: 0 8, 8, Index: The index tells us exactly what type of
More informationIntegers and Rational Numbers
A A Family Letter: Integers Dear Family, The student will be learning about integers and how these numbers relate to the coordinate plane. The set of integers includes the set of whole numbers (0, 1,,,...)
More informationLearning Log Title: CHAPTER 3: ARITHMETIC PROPERTIES. Date: Lesson: Chapter 3: Arithmetic Properties
Chapter 3: Arithmetic Properties CHAPTER 3: ARITHMETIC PROPERTIES Date: Lesson: Learning Log Title: Date: Lesson: Learning Log Title: Chapter 3: Arithmetic Properties Date: Lesson: Learning Log Title:
More informationChapter 1 & 2 Calculator Test Study Guide
Chapter 1 & 2 Calculator Test Study Guide Powers and Exponents 1) To put a number to the second power, simply hit the x 2 key, then enter. 2) To put a number to the third or a higher power, key in base,
More informationCSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College September 6, 2017 Outline Outline 1 Chapter 2: Data Abstraction Outline Chapter 2: Data Abstraction 1 Chapter 2: Data Abstraction
More informationAlgebra 1 Review. Properties of Real Numbers. Algebraic Expressions
Algebra 1 Review Properties of Real Numbers Algebraic Expressions Real Numbers Natural Numbers: 1, 2, 3, 4,.. Numbers used for counting Whole Numbers: 0, 1, 2, 3, 4,.. Natural Numbers and 0 Integers:,
More informationCS61A Lecture 9 Immutable Data Structures. Jom Magrotker UC Berkeley EECS July 2, 2012
CS61A Lecture 9 Immutable Data Structures Jom Magrotker UC Berkeley EECS July 2, 2012 COMPUTER SCIENCE IN THE NEWS Google unveils Glass at Google I/O, June 27 Prototypes available to developers at the
More information50 MATHCOUNTS LECTURES (6) OPERATIONS WITH DECIMALS
BASIC KNOWLEDGE 1. Decimal representation: A decimal is used to represent a portion of whole. It contains three parts: an integer (which indicates the number of wholes), a decimal point (which separates
More informationData Types and the main Function
COMP101 - UNC Data Types and the main Function Lecture 03 Announcements PS0 Card for Someone Special Released TODAY, due next Wednesday 9/5 Office Hours If your software has issues today, come to office
More informationLecture Notes, CSE 232, Fall 2014 Semester
Lecture Notes, CSE 232, Fall 2014 Semester Dr. Brett Olsen Week 11 - Number Theory Number theory is the study of the integers. The most basic concept in number theory is divisibility. We say that b divides
More informationLesson 1: Arithmetic Review
In this lesson we step back and review several key arithmetic topics that are extremely relevant to this course. Before we work with algebraic expressions and equations, it is important to have a good
More informationVARIABLES AND TYPES CITS1001
VARIABLES AND TYPES CITS1001 Scope of this lecture Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Primitive types Every piece of data
More informationBig Mathematical Ideas and Understandings
Big Mathematical Ideas and Understandings A Big Idea is a statement of an idea that is central to the learning of mathematics, one that links numerous mathematical understandings into a coherent whole.
More information7COM1023 Programming Paradigms
7COM Programming Paradigms Practical Answers Expressions We will commence by typing in some expressions to familiarise ourselves with the environment.. Type in the following and evaluate them by pressing
More informationTextbook. Topic 6: Functions. Motivation. What is a Function? What s a function? How can we use functions to write better software?
Textbook Topic 6: Functions What s a? How can we use s to write better software? Strongly Recommended Exercises The Python Workbook: 85, 86, 98 and 103 Recommended Exercises The Python Workbook: 84, 88,
More informationMini-Lesson 1. Section 1.1: Order of Operations PEMDAS
Name: Date: 1 Section 1.1: Order of Operations PEMDAS If we are working with a mathematical expression that contains more than one operation, then we need to understand how to simplify. The acronym PEMDAS
More informationPre-Algebra Notes Unit Five: Rational Numbers and Equations
Pre-Algebra Notes Unit Five: Rational Numbers and Equations Rational Numbers Rational numbers are numbers that can be written as a quotient of two integers. Since decimals are special fractions, all the
More informationLecture #24: Programming Languages and Programs
Lecture #24: Programming Languages and Programs A programming language is a notation for describing computations or processes. These range from low-level notations, such as machine language or simple hardware
More informationSOLUTION: Because the fractions have a common denominator, compare the numerators. 5 < 3
Section 1 Practice Problems 1. Because the fractions have a common denominator, compare the numerators. 5 < 3 So,. 2. 0.71 To compare these numbers, write both fractions as a decimal. 0.8 is greater than
More informationFlow Control. So Far: Writing simple statements that get executed one after another.
Flow Control So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow control allows the programmer
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationLecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1
Lecture #15: Generic Functions and Expressivity Last modified: Wed Mar 1 15:51:48 2017 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L of
More informationDownload Python from Any version will do for this class
Let s Start Python Let s Start! Download Python from www.python.org Any version will do for this class By and large they are all mutually compatible Recommended version: 2.1.1 or 2.2 Oldest version still
More information61A LECTURE 14 MULTIPLE REPRESENTATIONS
61A LECTURE 14 MULTIPLE REPRESENTATIONS Steven Tang and Eric Tzeng July 17, 2013 Generic Functions An abstrac/on might have more than one representa/on. Python has many sequence types: tuples, ranges,
More informationChapter 2 Working with Data Types and Operators
JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics
More informationCSCE 110: Programming I
CSCE 110: Programming I Sample Questions for Exam #1 February 17, 2013 Below are sample questions to help you prepare for Exam #1. Make sure you can solve all of these problems by hand. For most of the
More information61A LECTURE 14 MULTIPLE REPRESENTATIONS. Steven Tang and Eric Tzeng July 17, 2013
61A LECTURE 14 MULTIPLE REPRESENTATIONS Steven Tang and Eric Tzeng July 17, 2013 Generic Functions An abstrac*on might have more than one representa*on. Python has many sequence types: tuples, ranges,
More informationFIFTH GRADE Mathematics Curriculum Map Unit 1
FIFTH GRADE Mathematics Curriculum Map Unit 1 VOCABULARY algorithm area model Associative Property base braces brackets Commutative Property compatible numbers decimal decimal point Distributive Property
More informationIntroduction to Fractions
Introduction to Fractions Fractions represent parts of a whole. The top part of a fraction is called the numerator, while the bottom part of a fraction is called the denominator. The denominator states
More informationLesson 1: Arithmetic Review
Lesson 1: Arithmetic Review Topics and Objectives: Order of Operations Fractions o Improper fractions and mixed numbers o Equivalent fractions o Fractions in simplest form o One and zero Operations on
More informationMultiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left
Multiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left Dividing Decimals Quotient (answer to prob), Dividend (the # being subdivided) & Divisor
More informationSection A Arithmetic ( 5) Exercise A
Section A Arithmetic In the non-calculator section of the examination there might be times when you need to work with quite awkward numbers quickly and accurately. In particular you must be very familiar
More informationEE 152 Advanced Programming LAB 7
EE 152 Advanced Programming LAB 7 1) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of
More informationSection 1.2 Fractions
Objectives Section 1.2 Fractions Factor and prime factor natural numbers Recognize special fraction forms Multiply and divide fractions Build equivalent fractions Simplify fractions Add and subtract fractions
More informationGateway Regional School District VERTICAL ARTICULATION OF MATHEMATICS STANDARDS Grades K-4
NUMBER SENSE & OPERATIONS K.N.1 Count by ones to at least 20. When you count, the last number word you say tells the number of items in the set. Counting a set of objects in a different order does not
More informationProgramming Lecture 3
Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements
More informationCOMPETENCY 1.0 UNDERSTAND THE STRUCTURE OF THE BASE TEN NUMERATION SYSTEM AND NUMBER THEORY
SUBAREA I. NUMBERS AND OPERATIONS COMPETENCY.0 UNDERSTAND THE STRUCTURE OF THE BASE TEN NUMERATION SYSTEM AND NUMBER THEORY Skill. Analyze the structure of the base ten number system (e.g., decimal and
More informationPieNum Language Reference Manual
PieNum Language Reference Manual October 2017 Hadiah Venner (hkv2001) Hana Fusman (hbf2113) Ogochukwu Nwodoh( ocn2000) Index Introduction 1. Lexical Convention 1.1. Comments 1.2. Identifiers 1.3. Keywords
More informationcorgi Language Reference Manual COMS W4115
corgi Language Reference Manual COMS W4115 Philippe Guillaume Losembe (pvl2109) Alisha Sindhwani (as4312) Melissa O Sullivan (mko2110) Justin Zhao (jxz2101) October 27, 2014 Chapter 1: Introduction corgi
More informationUnit 2: Accentuate the Negative Name:
Unit 2: Accentuate the Negative Name: 1.1 Using Positive & Negative Numbers Number Sentence A mathematical statement that gives the relationship between two expressions that are composed of numbers and
More informationMultiplying and Dividing Rational Expressions
Page 1 of 14 Multiplying and Dividing Rational Expressions Attendance Problems. Simplify each expression. Assume all variables are nonzero. x 6 y 2 1. x 5 x 2 2. y 3 y 3 3. 4. x 2 y 5 Factor each expression.
More informationCSE 115. Introduction to Computer Science I
CSE 115 Introduction to Computer Science I Note about posted slides The slides we post will sometimes contain additional slides/content, beyond what was presented in any one lecture. We do this so the
More informationThe Pyth Language. Administrivia
Administrivia The Pyth Language Lecture 5 Please make sure you have registered your team, created SSH keys as indicated on the admin page, and also have electronically registered with us as well. Prof.
More informationMAT 003 Brian Killough s Instructor Notes Saint Leo University
MAT 003 Brian Killough s Instructor Notes Saint Leo University Success in online courses requires self-motivation and discipline. It is anticipated that students will read the textbook and complete sample
More informationLecture Numbers. Richard E Sarkis CSC 161: The Art of Programming
Lecture Numbers Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda To understand the concept of data types To be familiar with the basic numeric data types in Python To be able
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationCS3110 Spring 2017 Lecture 10 a Module for Rational Numbers
CS3110 Spring 2017 Lecture 10 a Module for Rational Numbers Robert Constable Abstract The notes and lecture start with a brief summary of the relationship between OCaml types, Coq types and logic that
More information4.3 Rational Thinking
RATIONAL EXPRESSIONS & FUNCTIONS -4.3 4.3 Rational Thinking A Solidify Understanding Task The broad category of functions that contains the function!(#) = & ' is called rational functions. A rational number
More informationBe careful when deciding whether to represent data as integers or floats, and be sure that you consider all possible behaviors in computation.
Table of Contents: 1. Integers and floats 2. for vs. while loops 3. Checking boolean conditions with if/else 4. Docstrings 5. Changing collections while iterating over them 6. Directly Accessing Instance
More informationFundamentals of Programming (Python) Object-Oriented Programming. Ali Taheri Sharif University of Technology Spring 2018
Fundamentals of Programming (Python) Object-Oriented Programming Ali Taheri Sharif University of Technology Outline 1. Python Data Types 2. Classes and Objects 3. Defining Classes 4. Working with Objects
More informationWhat is a Fraction? A fraction is a part or piece of something. The way we write fractions tells us the size of the piece we are referring to
October 0, 0 What is a Fraction? A fraction is a part or piece of something. The way we write fractions tells us the size of the piece we are referring to ⅝ is the numerator is the denominator is the whole
More informationPython Basics. Lecture and Lab 5 Day Course. Python Basics
Python Basics Lecture and Lab 5 Day Course Course Overview Python, is an interpreted, object-oriented, high-level language that can get work done in a hurry. A tool that can improve all professionals ability
More informationSection 3.2 Comparing and Ordering Fractions and Decimals. 1. Model fractions and/or decimals using blocks, fraction pieces, pattern blocks, etc.
Section 3.2 Comparing and Ordering Fractions and Decimals We will use several methods to compare and order fractions: 1. Model fractions and/or decimals using blocks, fraction pieces, pattern blocks, etc.
More informationComputing Seminar Introduction Oct
Computing Seminar Introduction Oct 6 2010 Outline today Programming/computing basics terminology, high level concepts (variables, control flow, input/output) Before next week... Make sure you can login
More informationJython. secondary. memory
2 Jython secondary memory Jython processor Jython (main) memory 3 Jython secondary memory Jython processor foo: if Jython a
More informationMath Content
2013-2014 Math Content PATHWAY TO ALGEBRA I Hundreds and Tens Tens and Ones Comparing Whole Numbers Adding and Subtracting 10 and 100 Ten More, Ten Less Adding with Tens and Ones Subtracting with Tens
More informationMultiplying and Dividing Rational Expressions
Multiplying and Dividing Rational Expressions Warm Up Simplify each expression. Assume all variables are nonzero. 1. x 5 x 2 3. x 6 x 2 x 7 Factor each expression. 2. y 3 y 3 y 6 x 4 4. y 2 1 y 5 y 3 5.
More informationProgramming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.
Plan for the rest of the semester: Programming We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. We saw earlier that computers
More informationRational Numbers: Multiply and Divide
Rational Numbers: Multiply and Divide Multiplying Positive and Negative Numbers You know that when you multiply a positive number by a positive number, the result is positive. Multiplication with negative
More informationFractions. Dividing the numerator and denominator by the highest common element (or number) in them, we get the fraction in its lowest form.
Fractions A fraction is a part of the whole (object, thing, region). It forms the part of basic aptitude of a person to have and idea of the parts of a population, group or territory. Civil servants must
More informationFifth Grade Math Rubric
Operations and Algebraic Thinking Support Needed Progressing Meets Writes, solves, and interprets numerical expressions guidance with and/or inconsistently writes, solves, and interprets numerical expressions.
More informationAdministrivia. Simple data types
Administrivia Lists, higher order procedures, and symbols 6.037 - Structure and Interpretation of Computer Programs Mike Phillips (mpp) Massachusetts Institute of Technology Project 0 was due today Reminder:
More informationWarm Up Simplify each expression. Assume all variables are nonzero.
Warm Up Simplify each expression. Assume all variables are nonzero. 1. x 5 x 2 3. x 6 x 2 x 7 x 4 Factor each expression. 2. y 3 y 3 y 6 4. y 2 1 y 5 y 3 5. x 2 2x 8 (x 4)(x + 2) 6. x 2 5x x(x 5) 7. x
More informationIs the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd
Is the statement sufficient? If both x and y are odd, is xy odd? Is x < 0? 1) xy 2 < 0 Positives & Negatives Answer: Yes, xy is odd Odd numbers can be represented as 2m + 1 or 2n + 1, where m and n are
More information