DOC PREVIEW
Berkeley COMPSCI 61A - Lecture 12

This preview shows page 1-2-3-4-5-6-40-41-42-43-44-81-82-83-84-85-86 out of 86 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 86 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

61A Lecture 12Monday, September 26Monday, September 26, 2011Implementing Dice2http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentation2http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,2http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,•Primality tests2http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,•Primality tests•Machine learning techniques2http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,•Primality tests•Machine learning techniques2http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,•Primality tests•Machine learning techniques2def make_dice(sides=6): seed = 1 def dice(): nonlocal seed seed = (16807 * seed) % 2147483647 return seed % sides + 1 return dicehttp://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,•Primality tests•Machine learning techniques2def make_dice(sides=6): seed = 1 def dice(): nonlocal seed seed = (16807 * seed) % 2147483647 return seed % sides + 1 return dice231 - 1http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,•Primality tests•Machine learning techniques2def make_dice(sides=6): seed = 1 def dice(): nonlocal seed seed = (16807 * seed) % 2147483647 return seed % sides + 1 return dice231 - 1http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Implementing DiceRandom numbers are useful for experimentationThey also appear in lots of algorithms, e.g.,•Primality tests•Machine learning techniques2def make_dice(sides=6): seed = 1 def dice(): nonlocal seed seed = (16807 * seed) % 2147483647 return seed % sides + 1 return dice231 - 1S.K. Park and K.W. Miller, " Random Number Generators: Good Ones Are Hard To Find", Communications of the ACM, October 1988, pp. 1192-1201.http://www.math.utah.edu/~pa/Random/Random.htmlMonday, September 26, 2011Referential Transparency, Lost3Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3mul(add(2, mul(4, 6)), add(3, 5))Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3mul(add(2, mul(4, 6)), add(3, 5))mul(add(2, 24 ), add(3, 5))Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3mul(add(2, mul(4, 6)), add(3, 5))mul(add(2, 24 ), add(3, 5))mul( 26 , add(3, 5))Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3• Re-binding operations violate the condition of referential transparency because they let us define functions that do more than just return a value; we can change the environment, causing values to mutate.mul(add(2, mul(4, 6)), add(3, 5))mul(add(2, 24 ), add(3, 5))mul( 26 , add(3, 5))Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3• Re-binding operations violate the condition of referential transparency because they let us define functions that do more than just return a value; we can change the environment, causing values to mutate.mul(add(2, mul(4, 6)), add(3, 5))mul(add(2, 24 ), add(3, 5))mul( 26 , add(3, 5))Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3• Re-binding operations violate the condition of referential transparency because they let us define functions that do more than just return a value; we can change the environment, causing values to mutate.mul(add(2, mul(4, 6)), add(3, 5))mul(add(2, 24 ), add(3, 5))mul( 26 , add(3, 5))Monday, September 26, 2011Referential Transparency, Lost• Expressions are referentially transparent if substituting an expression with its value does not change the meaning of a program.3• Re-binding operations violate the condition of referential transparency because they let us define functions that do more than just return a value; we can change the environment, causing values to mutate.mul(add(2, mul(4, 6)), add(3, 5))mul(add(2, 24 ), add(3, 5))mul( 26 , add(3, 5))DemoMonday, September 26, 2011Implementing a Mutable Container Object4def make_container(contents): def get(): return contents def put(value): nonlocal contents contents = value return get, putget, put = make_container('Hi')Monday, September 26, 2011Implementing a Mutable Container Object4def make_container(contents): def get(): return contents def put(value): nonlocal contents contents = value return get, putget, put = make_container('Hi')make_container(contents):make_container:...Monday, September 26, 2011make_container('Hi')Implementing a Mutable Container Object4def make_container(contents): def get(): return


View Full Document

Berkeley COMPSCI 61A - Lecture 12

Documents in this Course
Lecture 1

Lecture 1

68 pages

Midterm

Midterm

5 pages

Midterm

Midterm

6 pages

Lecture 35

Lecture 35

250 pages

Lecture 14

Lecture 14

125 pages

Lecture 2

Lecture 2

159 pages

Lecture 6

Lecture 6

113 pages

Lecture 3

Lecture 3

162 pages

Homework

Homework

25 pages

Lecture 13

Lecture 13

117 pages

Lecture 29

Lecture 29

104 pages

Lecture 11

Lecture 11

173 pages

Lecture 7

Lecture 7

104 pages

Midterm

Midterm

6 pages

Midterm

Midterm

6 pages

Lecture 8

Lecture 8

108 pages

Lab 4

Lab 4

4 pages

Lecture 7

Lecture 7

52 pages

Lecture 20

Lecture 20

129 pages

Lecture 15

Lecture 15

132 pages

Lecture 9

Lecture 9

95 pages

Lecture 30

Lecture 30

108 pages

Lecture 17

Lecture 17

106 pages

Load more
Download Lecture 12
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 12 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 12 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?