Function


Math

Expresses the relationship between two or more terms called variables and is typically written in the form of an equation. If each value of x can be associated with one value of y, then y is a function of x. y is the dependent variable. A function passes the vertical line test.

  • y = 2x ~ this is a single-variable function, since y is only dependent on one other variable.
  • y = mx + c ~ m and c are constants or coefficents.
  • A = lw ~ two-variable function, plotted on a three-dimensional graph
  • V = lwh ~ plotted on a graph in four dimensions, which requires imagination
  • f(x) = ax ~ an exponential function

(Programming Game AI by Example by Mat Buckland, 2005. Page 3-5, 18.01.1x)

  • Domain - set of allowable input values
  • Range - set of all possible output values
  • Interval notation is often used to express sets of numbers like domains and ranges, denoting closed intervals, open intervals, and half-open half-closed intervals.

(18.01.1x)

Programming

A mapping from values of one type to values of another type.

In Haskell, argument and result types are unrestricted. Functions with multiple arguments or results are possible using lists or tuples.

  • not :: Bool -> Bool
  • isDigit :: Char -> Bool
  • another
  • add :: (Int,Int) -> Int
  • add (x,y) = x+y
  • or
  • zeroto :: Int -> [Int]
  • zeroto n = [0..n]

(FP101x)

Topics