Index Ai Academy
Foundation · Foundation mathAlgebra

Functions: a rule from input to output

About 42 minLooking ahead: some prerequisites aren't done yet

Why this matters

A function is a rule that turns each input into exactly one output, like a machine. It's the most important idea in this whole section: a model is a function from inputs to predictions, and its loss is a function from weights to a single number. This lesson reads f(x) notation, turns a function into a table and a graph, and uses Python's lists and loops to search a table for the best value. You'll also draw your first graph in Python.

  • Read f(x) notation as a named rule, and work out a function's value for an input
  • Build a table of values, see it as a graph, and state a function's domain and range
  • Use lists, for loops, range, len and append in Python to tabulate a function, search for its smallest value and draw its graph
  • Treat a model's loss as a function of its weight, and find the best of ten weights
Quick check
Have a guess before you start. A machine doubles its input and then adds 1. What comes out when 5 goes in?

The math: a machine with a name

Purpose. Describe exactly how one quantity depends on another.

A function is a rule that gives exactly one output for each input. Picture a machine: a number goes in, the rule is applied, one number comes out.

Functions get names, usually f, g or p, and the input goes in brackets:

p(x)=5x−3p(1)=5×1−3=2p(x) = 5x - 3 \qquad p(1) = 5 \times 1 - 3 = 2

In plain words: p is the rule "times 5, take 3". p(1), read "p of 1", is what comes out when 1 goes in.

p(x) does not mean p times x. The brackets hold the input. It's exactly Python's def p(x): return 5 * x - 3, word for word.