In the last stage, students wrote some very simple functions - but more sophisticated functions demand a more thoughtful approach. The Design Recipe is a structured approach to writing functions that includes writing test cases to ensure that the function works as expected. Once students have mastered the Design Recipe process, they can apply it to any word problem they encounter.
- Use the Design Recipe to identify dependent variables, independent variables, and constants.
Common Core Math Standards
- F.BF.1: Write a function that describes a relationship between two quantities.
Additional standards alignment can be found at the end of this lesson
Activity: The Design Recipe
Materials, Resources, and Prep
For the Student
For the Teacher
This lesson has five new and important words:
- Design Recipe - a sequence of steps to document, test, and write functions.
- Purpose Statement - a brief description of what the 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.
The Design Recipe is a roadmap for defining functions, which programmers use to make sure the code they write does what they want it to do. Each step builds on the last, so any mistakes can be caught early in the process. This roadmap has a series of steps:
- Write a Contract that describes the word problem.
- Write Examples based on the contract.
- Define a function that matches the examples.
Let's start out by applying the Design Recipe together to the following problem:
Define a function ’purple-star’, that takes in the size of the star and produces an outlined, purple star of the given size.
Step 1 - The Contract
purple-star: Number -> Image
Be sure to include a good Name for each function, and remember that the Domain and Range can only include types like Numbers, Images, Strings, etc.
A Contract is the foundation for a function, which gives programmers just enough information to use it: the name of the function, the type (or types) of data it expects and the type of data it returns.
Step 2 - Examples
- Every Example begins with the name of the function. Where could you find the name of the function?
- Every Example has to include sample inputs. Where could you find out how many inputs this function needs, and what types they are?
- Every Example has to include an expression for what the function should do when given an input. Where could you look to find out what this function does?
Once you have two or more Examples, it should be easy to identify what has changed between them. In fact, the number of things that change should match the number of things in the function’s Domain: if the Domain has a Number and a String in it, then those two values should be the things that differ between your Examples.
Step 3 - Function Definition
By identifying what has changed between these Examples, we can define our actual function.
Challenge students to explain why this function does not need to know the color of the star, or whether or not it is solid. The main idea here is that the function already "knows" these things, so the only thing that is changing is the size of the star.
Remember that the Contract and Purpose Statement can be used to write the Examples, even if a programmer isn’t sure how to begin.
- Define a function ’spot’, that takes in a color and produces a solid circle of radius 50, filled in with that color.
- Define a function ’average’, which takes in two numbers and produces their average. (You may need to remind the students that to find the average of two numbers, they should be added together and divided by two.)
- Suppose 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.
Put students into groups of 3 - each member of the group will represent one step of the Design Recipe
Each group will work through a set of word problems using the Fast Functions Sheet. We recommend that you pull word problems from your own curriculum so that students can see how the Design Recipe can be used outside of programming. Make sure that each group member stays true to their role and that they work through the steps in the right order. If you don't have problems to use from your curriculum, there are a number of examples available in this lesson's slide deck.
Challenge students to explain their Examples (their function name, the number of inputs, their types and the type of the returned value). Make sure that the two Examples for each function have different input values! For each of these questions, students must be able to point to the specific part of their Contract as the justification for their Example.
Make sure students have chosen good variable names for their function definitions, and ask students to justify every part of the function body. The only acceptable answers should be "I copied this because it’s the same in both Examples", or "I used a variable name because it differs between Examples."
Once students have worked through the Fast Functions, you can have them use the full Blank Design Recipe Form to work through an word problems that they encounter in the future.
Common Core Math Standards
- 5.OA.1 - Use parentheses, brackets, or braces in numerical expressions, and evaluate expressions with these symbols.
- 5.OA.2 - Write simple expressions that record calculations with numbers, and interpret numerical expressions without evaluating them. For example, express the calculation “add 8 and 7, then multiply by 2” as 2 × (8 + 7). Recognize that 3 × (18932 + 921) is three times as large as 18932 + 921, without having to calculate the indicated sum or product.
- 6.NS.8 - Solve real-world and mathematical problems by graphing points in all four quadrants of the coordinate plane. Include use of coordinates and absolute value to find distances between points with the same first coordinate or the same second coordinate.
- 6.EE.9 - Use variables to represent two quantities in a real-world problem that change in relationship to one another; write an equation to express one quantity, thought of as the dependent variable, in terms of the other quantity, thought of as the independent variable. Analyze the relationship between the dependent and independent variables using graphs and tables, and relate these to the equation. For example, in a problem involving motion at constant speed, list and graph ordered pairs of distances and times, and write the equation d = 65t to represent the relationship between distance and time.
- 7.EE.4 - Use variables to represent quantities in a real-world or mathematical problem, and construct simple equations and inequalities to solve problems by reasoning about the quantities.
- 8.F.1 - Understand that a function is a rule that assigns to each input exactly one output. The graph of a function is the set of ordered pairs consisting of an input and the corresponding output.1
- 8.F.2 - Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions). For example, given a linear function represented by a table of values and a linear function represented by an algebraic expression, determine which function has the greater rate of change.
- A.CED.1 - Create equations and inequalities in one variable and use them to solve problems. Include equations arising from linear and quadratic functions, and simple rational and exponential functions.
- A.CED.2 - Create equations in two or more variables to represent relationships between quantities; graph equations on coordinate axes with labels and scales.
- A.CED.3 - Represent constraints by equations or inequalities, and by systems of equations and/or inequalities, and interpret solutions as viable or non- viable options in a modeling context. For example, represent inequalities describing nutritional and cost constraints on combinations of different foods.
- A.CED.4 - Rearrange formulas to highlight a quantity of interest, using the same reasoning as in solving equations. For example, rearrange Ohm’s law V = IR to highlight resistance R.
- F.IF.1 - Understand that a function from one set (called the domain) to another set (called the range) assigns to each element of the domain exactly one element of the range. If f is a function and x is an element of its domain, then f(x) denotes the output of f corresponding to the input x. The graph of f is the graph of the equation y = f(x).
- F.IF.2 - Use function notation, evaluate functions for inputs in their domains, and interpret statements that use function notation in terms of a context.
- F.IF.3 - Recognize that sequences are functions, sometimes defined recursively, whose domain is a subset of the integers. For example, the Fibonacci sequence is defined recursively by f(0) = f(1) = 1, f(n+1) = f(n) + f(n-1) for n ≥ 1.
- F.IF.4 - For a function that models a relationship between two quantities, interpret key features of graphs and tables in terms of the quantities, and sketch graphs showing key features given a verbal description of the relationship. Key features include: intercepts; intervals where the function is increasing, decreasing, positive, or negative; relative maximums and minimums; symmetries; end behavior; and periodicity.★
- F.IF.5 - Relate the domain of a function to its graph and, where applicable, to the quantitative relationship it describes. For example, if the function h(n) gives the number of person-hours it takes to assemble n engines in a factory, then the positive integers would be an appropriate domain for the function.★
- F.IF.6 - Calculate and interpret the average rate of change of a function (presented symbolically or as a table) over a specified interval. Estimate the rate of change from a graph.★
- F.IF.7 - Graph functions expressed symbolically and show key features of the graph, by hand in simple cases and using technology for more complicated cases.★
- F.IF.9 - Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions). For example, given a graph of one quadratic function and an algebraic expression for another, say which has the larger maximum.
- F.BF.1 - Write a function that describes a relationship between two quantities.
- F.BF.2 - Write arithmetic and geometric sequences both recursively and with an explicit formula, use them to model situations, and translate between the two forms.★
- F.LE.1 - Distinguish between situations that can be modeled with linear functions and with exponential functions.
- F.LE.2 - Construct linear and exponential functions, including arithmetic and geometric sequences, given a graph, a description of a relationship, or two input-output pairs (include reading these from a table).
Common Core Math Practices
- MP.1 - Make sense of problems and persevere in solving them.
- MP.2 - Reason abstractly and quantitatively.
- MP.3 - Construct viable arguments and critique the reasoning of others.
- MP.4 - Model with mathematics.
- MP.5 - Use appropriate tools strategically.
- MP.6 - Attend to precision.
- MP.7 - Look for and make use of structure.
- MP.8 - Look for and express regularity in repeated reasoning.