A total function is like a vending machine that always gives you a snack when you press a button, no matter what button you pick. A partial function, though, is more like a vending machine that sometimes doesn’t have the snack you want, if you pick the wrong button, it might just say “out of order.”
What’s a Function?
Imagine you have a toy box full of blocks. Each block has a number on it. If you give me a number, I’ll give you back a specific block. That's like a function, it takes something in (input) and gives you something out (output).
Now, if every number from 1 to 10 is matched with one of your blocks, that’s a total function, no matter what number I pick, there’s always a block waiting.
But if some numbers don’t have a matching block, like if the number 7 is missing, and you ask for it, then I can’t give you anything. That means it’s a partial function, not every input has an output, just some of them.
Examples
- A total function is like a vending machine that always gives you a snack when you press a button. A partial function is like a vending machine that sometimes runs out of snacks and doesn’t give anything.
Ask a question
See also
- What are higher-order predicates?
- What are reducing functions?
- What are partial functions?
- Dividing by zero?
- Does infinity exist in the real world?