Lesson 7: The Design Recipe
Overview
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.
Purpose
The Design Recipe process for writing functions introduces students to some best practices in software design that most don’t learn until college or later. By writing examples (or test cases, as they are often called in industry) before writing the body of the function students are following a practice called test-driven development. In TDD software developers write failing test cases before adding a new features, and then works on their code until the test cases pass. This ensures that developers stay focused on writing code that does what they set out to do while also putting in place automated testing that ensures the program continues working as expected while more features are added.
Agenda
Getting Started
Activity
Anchor Standard
Common Core Math Standards
- F.BF.1 - Write a function that describes a relationship between two quantities.
Objectives
Students will be able to:
- Use the Design Recipe to identify dependent variables, independent variables, and constants.
Links
For the Teacher
- CS in Algebra Lesson 9 Slide Deck - Slide Deck
For the Students
- Design Recipe Form - Worksheet
- Fast Functions - Worksheet
Vocabulary
- Constant - A fixed number in a relationship.
- Dependent Variable - A value that changes based on an independent variable.
- Design Recipe - A systematic sequence of steps to document, test, and write functions.
- Independent Variable - An input variable the is controlled by the user.
- Purpose Statement - A brief description of what a function does.
Teaching Guide
Getting Started
What is the Design Recipe?
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.
Activity
Collaborative Design
In this activity students in small groups will use the Design Recipe to work through the following problems:
- 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
- Contract
- Examples
- Function
Lesson Tip
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.”
Each group will work through a set of word problems using the Fast Functions - Fast Functions. 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.
Once students have worked through the Fast Functions, you can have them use the full Design Recipe Form to work through an word problems that they encounter in the future.
Standards Alignment
Common Core Math Standards
BF - Building Functions
- 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.★
CED - Creating Equations
- 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.
EE - Expressions And Equations
- 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.
F - Functions
- 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.
IF - Interpreting Functions
- 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.
LE - Linear, Quadratic, And Exponential Models★
- 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).
MP - Math Practices
- MP.1 - Mathematically proficient students start by explaining to themselves the meaning of a problem and looking for entry points to its solution. They analyze givens, constraints, relationships, and goals. They make conjectures about the form and meaning of the solution and plan a solution pathway rather than simply jumping into a solution attempt. They consider analogous problems, and try special cases and simpler forms of the original problem in order to gain insight into its solution. They monitor and evaluate their progress and change course if necessary. Older students might, depending on the context of the problem, transform algebraic expressions or change the viewing window on their graphing calculator to get the information they need. Mathematically proficient students can explain correspondences between equations, verbal descriptions, tables, and graphs or draw diagrams of important features and relationships, graph data, and search for regularity or trends. Younger students might rely on using concrete objects or pictures to help conceptualize and solve a problem. Mathematically proficient students check their answers to problems using a different method, and they continually ask themselves, "Does this make sense?" They can understand the approaches of others to solving complex problems and identify correspondences between different approaches.
- MP.2 - Mathematically proficient students make sense of quantities and their relationships in problem situations. They bring two complementary abilities to bear on problems involving quantitative relationships: the ability to decontextualize—to abstract a given situation and represent it symbolically and manipulate the representing symbols as if they have a life of their own, without necessarily attending to their referents—and the ability to contextualize, to pause as needed during the manipulation process in order to probe into the referents for the symbols involved. Quantitative reasoning entails habits of creating a coherent representation of the problem at hand; considering the units involved; attending to the meaning of quantities, not just how to compute them; and knowing and flexibly using different properties of operations and objects.
- MP.3 - Mathematically proficient students understand and use stated assumptions, definitions, and previously established results in constructing arguments. They make conjectures and build a logical progression of statements to explore the truth of their conjectures. They are able to analyze situations by breaking them into cases, and can recognize and use counterexamples. They justify their conclusions, communicate them to others, and respond to the arguments of others. They reason inductively about data, making plausible arguments that take into account the context from which the data arose. Mathematically proficient students are also able to compare the effectiveness of two plausible arguments, distinguish correct logic or reasoning from that which is flawed, and—if there is a flaw in an argument—explain what it is. Elementary students can construct arguments using concrete referents such as objects, drawings, diagrams, and actions. Such arguments can make sense and be correct, even though they are not generalized or made formal until later grades. Later, students learn to determine domains to which an argument applies. Students at all grades can listen or read the arguments of others, decide whether they make sense, and ask useful questions to clarify or improve the arguments.
- MP.4 - Mathematically proficient students can apply the mathematics they know to solve problems arising in everyday life, society, and the workplace. In early grades, this might be as simple as writing an addition equation to describe a situation. In middle grades, a student might apply proportional reasoning to plan a school event or analyze a problem in the community. By high school, a student might use geometry to solve a design problem or use a function to describe how one quantity of interest depends on another. Mathematically proficient students who can apply what they know are comfortable making assumptions and approximations to simplify a complicated situation, realizing that these may need revision later. They are able to identify important quantities in a practical situation and map their relationships using such tools as diagrams, two-way tables, graphs, flowcharts and formulas. They can analyze those relationships mathematically to draw conclusions. They routinely interpret their mathematical results in the context of the situation and reflect on whether the results make sense, possibly improving the model if it has not served its purpose.
- MP.5 - Mathematically proficient students consider the available tools when solving a mathematical problem. These tools might include pencil and paper, concrete models, a ruler, a protractor, a calculator, a spreadsheet, a computer algebra system, a statistical package, or dynamic geometry software. Proficient students are sufficiently familiar with tools appropriate for their grade or course to make sound decisions about when each of these tools might be helpful, recognizing both the insight to be gained and their limitations. For example, mathematically proficient high school students analyze graphs of functions and solutions generated using a graphing calculator. They detect possible errors by strategically using estimation and other mathematical knowledge. When making mathematical models, they know that technology can enable them to visualize the results of varying assumptions, explore consequences, and compare predictions with data. Mathematically proficient students at various grade levels are able to identify relevant external mathematical resources, such as digital content located on a website, and use them to pose or solve problems. They are able to use technological tools to explore and deepen their understanding of concepts.
- MP.6 - Mathematically proficient students try to communicate precisely to others. They try to use clear definitions in discussion with others and in their own reasoning. They state the meaning of the symbols they choose, including using the equal sign consistently and appropriately. They are careful about specifying units of measure, and labeling axes to clarify the correspondence with quantities in a problem. They calculate accurately and efficiently, express numerical answers with a degree of precision appropriate for the problem context. In the elementary grades, students give carefully formulated explanations to each other. By the time they reach high school they have learned to examine claims and make explicit use of definitions.
- MP.7 - Mathematically proficient students look closely to discern a pattern or structure. Young students, for example, might notice that three and seven more is the same amount as seven and three more, or they may sort a collection of shapes according to how many sides the shapes have. Later, students will see 7 × 8 equals the well remembered 7 × 5 + 7 × 3, in preparation for learning about the distributive property. In the expression x2 + 9x + 14, older students can see the 14 as 2 × 7 and the 9 as 2 + 7. They recognize the significance of an existing line in a geometric figure and can use the strategy of drawing an auxiliary line for solving problems. They also can step back for an overview and shift perspective. They can see complicated things, such as some algebraic expressions, as single objects or as being composed of several objects. For example, they can see 5 - 3(x - y)2 as 5 minus a positive number times a square and use that to realize that its value cannot be more than 5 for any real numbers x and y.
- MP.8 - Mathematically proficient students notice if calculations are repeated, and look both for general methods and for shortcuts. Upper elementary students might notice when dividing 25 by 11 that they are repeating the same calculations over and over again, and conclude they have a repeating decimal. By paying attention to the calculation of slope as they repeatedly check whether points are on the line through (1, 2) with slope 3, middle school students might abstract the equation (y - 2)/(x - 1) = 3. Noticing the regularity in the way terms cancel when expanding (x - 1)(x + 1), (x - 1)(x2 + x + 1), and (x - 1)(x3 + x2 + x + 1) might lead them to the general formula for the sum of a geometric series. As they work to solve a problem, mathematically proficient students maintain oversight of the process, while attending to the details. They continually evaluate the reasonableness of their intermediate results.
NS - The Number System
- 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.
OA - Operations And Algebraic Thinking
- 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.
Q - Quantities
- N.Q.1 - Use units as a way to understand problems and to guide the solution of multi-step problems; choose and interpret units consistently in formulas; choose and interpret the scale and the origin in graphs and data displays.
- N.Q.2 - Define appropriate quantities for the purpose of descriptive modeling.