โ”€โ”€โ”€โœฑ*.๏ฝก:๏ฝกโœฑ*.:๏ฝกโœง*.๏ฝกโœฐ*.:๏ฝกโœง*.๏ฝก:๏ฝก*.๏ฝกโœฑ โ”€โ”€โ”€

A function is a special relationship from ๐ด to ๐ต, where ๐ด and ๐ต are both sets, where elements of ๐ด relate to exactly one element of ๐ต.

Each element in the domain (set ๐ด) maps to at least one element in the codomain (set ๐ต). No element in the domain can be mapped to more than one element in the codomain.

Terms

  • Domain โ†’ the values that ๐‘ฅ can be in ๐‘“(๐‘ฅ)=๐‘ฆ
  • Codomain โ†’ the set of values ๐‘ฆ that can be in ๐‘“(๐‘ฅ)=๐‘ฆ
  • Range โ†’ all values of ๐‘ฆ that ๐‘“(๐‘ฅ)=๐‘ฆ produces for a given ๐‘ฅ

Examples

  • Valid Function โ†’ ๐‘“:BankAccountNumberโ†’BankAccountInfo
  • Invalid Function โ†’ ๐‘“:ยฐFโ†’ยฐCยฑ5

Total Functions

  • Also known as โ€œdefined everywhere functionsโ€
  • Every element in the domain is mapped to an element in the codomain, such as
  • Total Function โ†’ ๐‘“(๐‘ฅ)=๐‘ฅ2 (๐‘“:โ„โ†’โ„)
  • Partial Function โ†’ ๐‘“(๐‘ฅ)=1๐‘ฅ (๐‘“:โ„โ†’โ„) โ†’ only defined for โ„โ‰ 0, not โ„

Onto Function

  • Every element in the codomain is mapped to at least one element in the domain

One to One Function

  • Every element in the codomain is mapped to at most one element in the domain

Inverse of a Function

  • A function ๐‘“ is invertible if and only if ๐‘“ is both one-to-one and onto.
    • Given ๐‘ฆ, one can deduce ๐‘ฅ
  • ๐‘“(๐‘ฅ)=๐‘ฅ+2โ†’๐‘“โˆ’1(๐‘ฆ)=๐‘ฆโˆ’2
    • ๐‘“(5)=5+2=7โ†’๐‘“โˆ’1(7)=7โˆ’2=5

One Way Function

  • Given ๐‘ฆ, one cannot deduce ๐‘ฅ

Hashing Functions

  • Encryption can be decrypted (two-way function)
  • Hashed passwords cannot be decrypted (one-way function)

Function Composition

  • Functions can be combined/nested with the syntax ๐‘“(๐‘”(๐‘ฅ)) or (๐‘“โˆ˜๐‘”)(๐‘ฅ)
  • ๐‘”(๐‘“(๐‘ฅ)):๐ดโ†’๐ถ,๐‘“(๐‘ฅ):๐ดโ†’๐ต,๐‘”(๐‘ฅ):๐ตโ†’๐ถ

โ”€โ”€โ”€โœฑ*.๏ฝก:๏ฝกโœฑ*.:๏ฝกโœง*.๏ฝกโœฐ*.:๏ฝกโœง*.๏ฝก:๏ฝก*.๏ฝกโœฑ โ”€โ”€โ”€