Skip to main content

CSC 151.01, Class 17: Boolean Values and Predicate Procedures

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Fun with trig
    • Questions
  • Leftovers: Lists of drawings
  • A new type: Boolean values
  • Lab.

News / Etc.

  • New partners!
  • More talking than normal today, as scary as that is.
  • I plan to return exam 1 this evening. I will also distribute some notes on the exam and an updated set of grades.
  • I will hold class on March 1. I will not penalize you from missing provided you send me a short summary of what you did during class time.
    • “Sam, I spent class time contemplating the best approach to making a positive difference in our modern world.”
    • “Sam, I spent class time listening to a speaker suggesting ways to make our nation inclusive.”

Rotating reminders

  • Use our tutors! We have tutors available Sunday through Thursday evening from 7-10 p.m. in Science 3813/15.

Upcoming Work

Extra credit (Academic/Artistic)

  • CS Table, Tuesday at noon, 21 Feb 2017. Net neutrality. Reading packets should be available outside Curtsinger’s office or Orsera’s office.
  • NEW Women in CS, Tuesday, 21 February 2017: Applying for GHC Scholarships and more! (All are welcome to attend.)
  • Thursday extras, Thursday, 23 Feb 2017, 4:15 p.m., Science 3821: The Future of MathLAN
  • Met Opera Live in HD showing of Rusalka, Saturday, Feb. 25. Talk 11:30-noon, opera noon-3pmish.
  • Prazak Quartet, Tuesday, 28 February 2017, 7:30 p.m., Herrick.

Extra credit (Peer)

  • NEW Ritalin Test squad, 2-4pm Saturday, Bucksbaum, The Wall
  • Host a prospective student. (March 5, April 8, April 23)
    • Get a coupon to a place that is not open or a place with no apostrophes.
    • Email [ohc]

Good things to do

  • Grinnell Equestrian Club Drill Team bake sale, 20 February 2017, 11am-2pm and 4pm-9pm.

The joy of trig.

  • Remember SOHCAHTOA!
  • For a circle, you can find the x and y coordinates of any point around the edge of the circle by
    • yoffset = r*sin(theta)
    • xoffset = r*cos(theta)
  • For an ellipse, we use a very similar formula.
    • yoffset = rvert*sin(theta)
    • xoffset = rhoriz*cos(theta)
    • So if the center is at (x,y), the point at the edge of the ellipse that is at angle theta from the positive x axis is at
      • (x + rhorizcos(theta), y + rvertsin(theta))
    • If the drawing is at (x,y), we hshift by rhorizcos(theta) and vshift by rvertsin(theta)

Questions

When is it a good thing to get the wrong answer?
For example, if we are transforming an image, we might be okay with a black or white pixel for “incorrect computation”, rather than having the whole program stop.

Review: Lists of drawings

Two minutes with your partner: What do you see as the key ideas from the lists of drawings lab?

  • Lists are collections of values.
    • For now, they are homogeneous - all the values are the same type.
  • They let us do a lot of computation at once. A form of repetition. You don’t have to type the same thing again and again and again
  • We can use map to do that computation.
    • (map single-parameter-proc lst) applies the procedure to each element of the list and gives us a new list with the results of that procedure.
    • (map two-parameter-proc lst1 lst2) applies the procedure to corresponding pairs of elements of the two lists and gives us a new list with the results of that procedure.
      • Note that both lists must have the same length.
  • We have multiple ways to make lists
    • (list val val val val)
    • (make-list N val) - N identical copies.
    • (iota N) - (list 0 1 2 …. N-1)
  • Fun with map and colors
    > (map irgb-add
         (map color->irgb (list "red" "salmon" "grey" "orange" "olive" "teal"))
         (make-list 6 (irgb 50 0 20)))
    '(16711700 16744582 11698324 16753940 11698196 3309716)
    > (map irgb->string
         (map irgb-add
         (map color->irgb (list "red" "salmon" "grey" "orange" "olive" "teal"))
         (make-list 6 (irgb 50 0 20))))
    '("255/0/20"
    "255/128/134"
    "178/128/148"
    "255/165/20"
    "178/128/20"
    "50/128/148")
    
  • Using the drawing procedures and long lists of drawings, we can make fairly interesting images.

A new type: Boolean values

Two minutes with your partner: You are encountering a new type. Ask and answer the four questions.

Note that “What are the four questions?” is not one of the four questions.

Why do we use this new type?
When we want to discuss yes/no or true/false situations. Useful for reasoning, probably for some kinds of tests and conditionals.
What values can we express?
True is #t. False is #f. The two are amazingly hard to distinguish when you have bad handwriting. Anything that is neither #t nor #f is considered “truish”.
What operations can we apply to this new type?
and, or, not
We can also compute Boolean results with equal? =, <=, and many many more comparators.
How does Scheme represent these values back to us?
More or less the same way we represent them to Scheme: #t and #f.

Lab

  • Yes, it’s weird that the compartor comes at the front. Deal. There are some advantages, such as the ability to write (<= 0 x 255).
  • Can you solve exercise 3 without using lambda?
  • If the average of the three components of c1 is less than the average of the three components of c2, what does that tell you about the relationship of the sum of the three components of c1 to the sum of the three components of c2. (Or vice versa?)
  • Writeup: Exercise 2

Writeup

Write up exercise 2 from the lab on Boolean values and predicate procedures.

Send your solution to csc151-01-grader@grinnell.edu.

Title your email CSC 151.01 Writeup for Class 17 (YOUR FULL NAMES).