1 of 17

Computer Science in Algebra

2 of 17

The Design Recipe

Writing intelligent functions, intelligently

3 of 17

Vocab

  • Design Recipe - a sequence of steps to document, test, and write functions
  • Purpose Statement - a brief description of what a function does
  • Independent Variable - The value that the experimenter controls. The input.
  • Dependent Variable - The value that changes based on the independent variable. The output.
  • Constant - A fixed number in a relationship.

4 of 17

Roadmap to Function-land

  1. Write a Contract that describes the problem
  2. Write Examples based on the Contract
  3. Define a Function that matches the examples

5 of 17

Design Recipe Step 1

  • Takes an argument for size (what type should it be?)
  • Returns an outlined purple star (what type is that?)

purple-star: Number -> Image

Define a function ’purple-star’ that takes in the size of the star and returns an outlined, purple star of the given size.

6 of 17

Design Recipe Step 1

  • Takes a single argument (what type should it be?)
  • Returns a value 50 less than the argument (what type is that?)

50less: Number -> Number

Write a function called “50less” that takes in a number, and returns a number that is 50 less.

7 of 17

Design Recipe Step 2a

50less(45) = 45 - 50

Write an example of what your function should produce, given some input (in this case 45)

8 of 17

Design Recipe Step 2b

50less(70) = 70 - 50

Write another example of what your function should produce, given some input (in this case 70)

9 of 17

Design Recipe Step 2c

50less(45) = 45 - 50

50less(70) = 70 - 50

Compare the two examples to see what changes

10 of 17

Design Recipe Step 3

Write a function called “50less” that takes in a number, and returns a number that is 50 less.

50less(x) = x - 50

11 of 17

Design Recipe Step 1

  • Takes a single argument (what type should it be?)
  • Returns a solid purple star of that size

purple-star: Number -> Image

Define a function ’purple-star’ that takes in the size of the star and returns an solid, purple star of the given size.

12 of 17

Design Recipe Step 2a

purple-star(45) = star(45, “solid”, “purple”)

Write an example of what your function should produce, given some input (in this case 45)

13 of 17

Design Recipe Step 2b

purple-star(120) = star(120, “solid”, “purple”)

Write another example of what your function should produce, given some input (in this case 120)

14 of 17

Design Recipe Step 2c

Compare the two examples

size

15 of 17

Design Recipe Step 3

Define a function ’purple-star’ that takes in the size of the star and returns an solid, purple star of the given size.

16 of 17

Collaborative Design

Each member of your group will take on one role:

  • Contract
  • Examples
  • Function

Use the Collaborative Design Recipe Worksheets to complete the following problems

17 of 17

Collaborative Design

  1. Define a function ’spot’, that takes in a color and produces a solid circle of radius 50, filled in with that color
  2. To find the average of two numbers, they should be added together and divided by two. Define a function ’average’, which takes in two numbers and produces their average
  3. A company logo is a word drawn in big, red letters, rotated some number of degrees. Define a function ’logo’, that takes in a company name and a rotation, and produces a logo for that company