python

Opening Days 2

Announcements

  • Welcome to IDS-101-13: Thinking Machines!
  • Opening Days: Day 2... Did you?
    • Get ~8 hours of sleep
    • Drink water
    • Eat at least one vegetable
    • Wash your hands
  • I sure hope you have a computer today.
    • If not, we improvise
  • How about those machines that might be thinking, eh?
    • Today's lecture loosely adapted from here.

Python

  • This semester we will use Python
  • Python is a language, but a novel kind of language.
    • Languages like English, Mandarin, Arabic are natural languages
      • They emerged as a result of historical and cultural processes.
      • They are ill-defined - it is ambigious whether a well-formed English sentence may terminate with a preposition.
      • They (usually) are well suited to vocalization or some other form of human communication, like sign language
    • Python is a constructed language
      • Languages like Elvish, Klingon, and JavaScript are constructed by linguistics for some purpose.
      • They are designed, rather than evolved.
      • Often they are precisely defined by community groups of thinking humans maintain a ruleset followed by thinking machines.
      • Many constructed languages are programming or scripting languages.
        • These languages are intended to be interpreted by computers rather than vocalized.

Python

  • This semester we will use Python
  • Python is a language, but a novel kind of language.
    • Languages like English, Mandarin, Arabic are natural languages
    • Python is a constructed language
  • We can differentiate thinking humans from thinking machines in perhaps a similar way.
    • Humans are natural thinkers.
      • Humans and human culture emerged consistent with naturalistic process over time.
    • Machines are constructed thinkers.
      • Machines are designed, engineered, and ultimately constructed by some other entity (humans).

Be sure to introduce yourselves!

Group 1Group 2Group 3Group 4

Colab

  • Take notes
    • Navigate to https://colab.research.google.com
    • Make a "New Notebook"
    • Name it something, like CC_8_22, you'll remember
    • For each question, +Text and record
    • You can remove the "Code" block by clicking the trashcan
    • Share with your group and with me!

Question #1

How do I understand myself in relation to thought and language?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Question #2

How do I understand myself in relation to nature and construction?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Question #3

How would I imaging a thinking machine understand the self in relation to nature and construction?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Question #4

How would I imaging a thinking machine understand the self in relation to thought and language?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Thinking and Expressing

  • As humans, we are accustomed to vocalization and textual expression between one another.
    • Through natural languages.
  • How might we expect a thinking machine to express thought?
    • Through constructed and especially programming languages.

Hello, World!

  • Let's consider a famous example: the "Hello, World!" program
  • Go into your Colab notebook (perhaps a copy of the group notebook)
  • Create a new "Text" block that reads:
    • "Exercise A.1 Have Python print Hello, World! to the screen."
    • Use double stars ** to click the "B" button to make the exercise name bold.
    • Use ` tick marks or click the "<>" button to style "Hello, World!" differently, to denote it is "printed".
  • Create a new "Code" block.
    • You will be prompted: Start coding or g͟e͟n͟e͟r͟a͟t͟e with AI.
    • Determine how to make the "Hello, World!" program.
      • You may chat with the AI.
      • You may read the Wikipedia link
      • You may use other resources at your disposal.
    • Once you have successfully written the program, add another "Text" block explaining your thought process.

Hello, World!

  • Here is a lightly redacted example:

  • What do you notice?
    • What does this tell you about "generate"?

Hello, You!

  • Create a new "Text" block that reads:
    • "Exercise A.2 Have Python print your preferred name to the screen."
  • Create a new "Code" block.
    • You will be prompted: Start coding or g͟e͟n͟e͟r͟a͟t͟e with AI.
    • Determine how to complete this task.
      • Will you use the same steps as last time?
      • Has your previous experience informed how you work with machines?
      • What have you learned?
    • Once you have successfully written the program, add another "Text" block explaining your thought process.

On Colab

  • Exercise A.3 Learn a bit more about Colab.
  • Figure out how to:
    • Save a notebook.
    • Load a notebook.
      • Load a brand new notebook.
      • Load a notebook you saved in Google Drive
      • Load a notebook you saved on your computer.
    • Share a notebook with your instructors and peers.
    • Write and format text in "Text" blocks.
      • Bold
      • Italicize
      • Underline
      • Quote
      • Code, and
      • Hyperlink (perhaps to Wikipedia or OpenAI chat you used to figure something out)
    • Change between "Text" and "Code" blocks using only the keyboard shortcuts.

Question #5

How did you decide whether and how to use AI to generate your responses to A.1, A.2, and/or A.3?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Arithmetic

  • Compared to humans, I find machines are much better at doing what I call "arithmetic".
  • I do arithmetic in my life when I'm trying to estimate when to leave my home to reach campus.
    • I enter I-5 at mile 298.
    • I exit I-5 at mile 260.
    • I-5 has a 55 mph speedlimit from 298 to 289 then 65.
    • It takes ~40 minutes to get to 260.
  • Or I can ask a computer. (298 - 289) * (55/60) + (289-260) * (65/60) 39.666666666666664
    • Oh wow - that's a lot faster, easier, more accurate, and more trustworthy.
  • To ease into approaching how machines may think we'll start with arithmetic:
    • It's easy for machines.
    • It can be useful for us.

Arithmetic

  • Python has many of the expected arithmetic operations, and some extra fun* ones too.
    • Addition: +
    • Subtraction: -
    • Multiplication: *
    • Division: /
  • And some and some extra fun* ones too.
    • Integer Division /
      • 5/2 is 2.5, but 5//2 is 2 (an integer, or whole number)
    • Modulo %
      • 5%2 is 1, but 4%2 is 0 (Modulo is the remainder)
    • Exponentiation **
      • 5**2 is 25, 5^2 is... something else.

Question #6

Can you think of a question you've left unanswered to because the arithmetic to answer them felt too daunting?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Operations

  • Exercise A.4 Testing operations.
  • Take two numbers: 123456789 and 12345 (selected to be easy to type)
  • Estimate and record your estimate of the value from using each of the arithmetic operations over these two values.
  • Using "Code" blocks in Colab, calculate the results.
    • 123456789 + 12345 (Addition)
    • 123456789 - 12345 (Subtraction)
    • 123456789 * 12345 (Multiplication)
    • 123456789 / 12345 (Division)
    • 123456789 // 12345 (Integer Division)
    • 123456789 % 12345 (Modulo)
    • 123456789 ** 12345 (Exponentiation)
      • Take special note of what happens here.
    • 123456789 ^ 12345 (Something else)
      • Describe vaguely what you think might be happening here.

Variables

  • We can also use variables in Python.
  • There are some restrictions on names - mostly that they can't contain spaces.
    • We can use single letter names, like =
    • We can use underscores as spaces, also called "snake case", like my_variable
    • We can use capitalization to start words, also called "camel case", like myVariable
  • We assign the value of a variable =
      x = 1
    • There must be a valid variable name on the left side of the "="
    • There must be some valid value on the right side
  • It's important to different assignment "single equals" "=" from equality testing "double equals" "=="

Variables

  • Exercise A.5 One or two equal signs.
  • Select any two integers and assign them to any two variable names, such as "x" or "y"
    • It will help latter if the first value is much larger than the second, but you can always change latter.
  • Calculate the integer "quotient" (the result of integer divison) and remainder of the two values
    • What operations should you use?
    • Store the result of each in a variable, for latter
  • Use "double equals" to check if
    • the smaller value (say, y)
    • times the quotient (say, q)
    • plus the remainder (say, r)
    • is equal to the larger value (say, x)

Question #7

What do you like or dislike about Python compared to other ways you've performed arithmetic in the past?
  • Think about a possible answer on your own
  • Discuss your answers with the rest of the group
  • Record a summary of each group’s discussion

Homework

  • Homework 1 Pythagorean Triples
    • Write code to define positive integers a, b, and c of your own choosing.
    • Calculate a2, b2, and c2
    • Check to see if your three values form a Pythagorean Triple such that a2 + b2 = c2.
    • Have Python print True or False to verify that you do, or do not, have a Pythagorean Triple defined.
    • Hint: You will need to use double and single equals as well as print()
  • You may make a copy of this Notebook and share it with me and anyone with whom you collaborate.
    • Give Shouvik and I edit permissions.
    • You may only give your peers view or comment permissions.