Class 10 - Notes

Upcoming Schedule

Project 2 is due at the beginning of class on Monday, 15 February.

Yuchi has office hours right after class today, and has scheduled additional office hours, 3-4:30pm on Sunday in Rice 532.

Slides

[Download (PPTX)]

Gravitational Waves

P. B. Abbot, et al., Observation of Gravitational Waves from a Binary Black Hole Merger. Physical Review Letters, 12 February 2016.

The Guardian, Gravitational waves: breakthrough discovery after two centuries of expectation, 11 February 2016. (Best popular explanation of what they did with figures.)

Science, Here’s the first person to spot those gravitational waves, 11 February 2016. (Interesting account of detecting the first signs of the gravitational waves. For security people, especially interesting to hear about how the lead researchers planned to inject fake signals into the data to keep the rest of the team alert, but this signal was detected before the injection system was actually in place.)

Git Repositories for LIGO project
signals.py

Programming with Lists

def make_pair(a, b):
    return [a, b]

def pair_first(pair):
    return pair[0]

def pair_last(pair):
    return pair[1]

# Let's make triples!

def make_triple(a, b, c):
    return make_pair(a, make_pair(b, c))

def triple_first(trip):
    return pair_first(trip)

def triple_second(trip):
    return pair_first(pair_last(trip))

def triple_third(trip):
    return pair_last(pair_last(trip))
# A list is a pair where the second part is a list, or None

def make_list(first, second):
    return make_pair(first, second)

def list_first(lst):
    return pair_first(lst)

def list_rest(lst):
    return pair_last(lst)

Defining List Procedures:

  1. Be very optimistic! Since lists themselves are recursive data structures, most problems involving lists can be solved with recursive procedures.

  2. Base Case. Think of the simplest version of the problem, something you can already solve. This is the base case. For lists, this is usually when the list is empty or a singleton.

  3. Recursive Case. Consider how you would solve the problem using the result for a slightly smaller version of the problem. This is the recursive case. For lists, the smaller version of the problem is usually the rest of the list. So, the procedure combines the result of doing something with the first element (p[0]) with making a recursive call on the rest of the elements (p[1:]).

def list_length(lst):
   # Returns the number of elements in lst.









Code

Here's the code in PythonTutor.com (try stepping backwards and forwards through the code to make sure you understand how list_length works):