Symbols, sets and functions
Symbols and functions (lesson 0.2.1)
0 of 7 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Sums and products
Sums and products (lesson 0.2.2)
0 of 9 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Coding exercise
Σ and Π as Python functions
Write two functions. Each takes a function term of the index, and the two limits.
sigma(term, lower, upper)returns .product(term, lower, upper)returns .
Both limits are included. When upper < lower there are no terms: return 0 for the sum and 1 for the product, as in lesson 0.2.2. The tests pass in functions such as lambda i: i**2.
See the tests
def test_sum_of_squares():
"""The sum of i² for i from 1 to 4 is 30"""
expect_close(sigma(lambda i: i**2, 1, 4), 30, what="sigma(lambda i: i**2, 1, 4)")
def test_upper_limit_included():
"""The upper limit is included: the sum of i for i from 1 to 100 is 5050"""
expect_close(sigma(lambda i: i, 1, 100), 5050, what="sigma(lambda i: i, 1, 100)")
def test_other_lower_limit():
"""The sum can start anywhere: 2i − 1 for i from 2 to 5 is 24"""
expect_close(sigma(lambda i: 2 * i - 1, 2, 5), 24, what="sigma(lambda i: 2*i - 1, 2, 5)")
def test_constant_term():
"""Adding 3 five times gives 15"""
expect_close(sigma(lambda i: 3, 1, 5), 15, what="sigma(lambda i: 3, 1, 5)")
def test_empty_sum():
"""An empty sum (upper below lower) is 0"""
expect_close(sigma(lambda i: i, 1, 0), 0, what="sigma(lambda i: i, 1, 0)")
def test_product_of_integers():
"""The product of i for i from 1 to 5 is 120"""
expect_close(product(lambda i: i, 1, 5), 120, what="product(lambda i: i, 1, 5)")
def test_growth_factors():
"""Three growth factors 1.1 × 1.2 × 1.3 multiply to 1.716"""
expect_close(product(lambda i: 1 + 0.1 * i, 1, 3), 1.1 * 1.2 * 1.3, what="product(lambda i: 1 + 0.1*i, 1, 3)")
def test_empty_product():
"""An empty product (upper below lower) is 1"""
expect_close(product(lambda i: i, 3, 2), 1, what="product(lambda i: i, 3, 2)")