Applied Discrete Structures by Alan Doerr & Kenneth Levasseur is licensed under a Creative Commons Attribution - Noncommercial - ShareAlike 3.0 United States License.
This document describes the basic ways in which a function can be represented with Sage. These topics are introduced in chapter 7 of Applied Discrete Structures.
In any computer program a function defined by a piece of code that will accept inputs and produce outputs. This is a bit more general than the mathematical concept of a function, but close enough to let use study the concept through programming. The function on the set defined by the ordered pairs can be represented as a dictionary:
Not every function can be easily defined by a formula, but this one can be using the standard synatax for Python/SageMath functions.
Not every SageMath function is a true function. For example, if the output is governed by a random number generator, the output for a given input will vary. Here is a function that returns 1 with probability and 0 with probability .