# An Interactive Laboratory Approach with Mathematica

A finite function is one whose domain and codomain are both finite sets. Finite functions can be completely defined by tables of pairs {(d, r)}, where d is an element of its domain and r is the corresponding element of its codomain. Binary functions are complete finite functions whose domains and codomains are Cartesian products over the binary set B = {0, 1}. Boolean functions are binary functions whose codomain is B. The tables below define three Boolean functions on two input variables and one Boolean function on one input variable. They are called truth tables because the values 1 and 0 are often associated with the values True and False, respectively. x y x ∧ y 0 0 0 0 1 0 1 0 0 1 1 1 x y x ∨ y 0 0 0 0 1 1 1 0 1 1 1 1 x y x ⊕ y 0 0 0 0 1 1 1 0 1 1 1 0 x x 0 1 1 0 The above tables define the AND function x∧y (its value is True when x and y are True), the OR function x ∨ y (its value is True when either x or y or both are True), the EXCLUSIVE OR function x ⊕ y (its value is True only when either x or y is True, that is, when x is True and y is False and vice versa), and the NOT function x (its value is True when x is False and vice versa). The notation f(2,1) ∧ : B2 → B, f(2,1) ∨ : B2 → B, f(2,1) ⊕ : B2 → B, f(1,1) ¬ : B → B for these functions makes explicit their number of input and output variables. We generally suppress the second superscript when functions are Boolean. The physical devices that compute the AND, OR, NOT, and EXCLUSIVE OR functions are called gates. Many computational problems are described by functions f : A∗ → C∗ from the (unbounded) set of strings over an alphabet A to the set of strings over a potentially different alphabet C. Since the letters in every finite alphabet A can be encoded as fixed-length strings over the binary alphabet B = {0, 1}, there is no loss of generality in assuming that functions are mappings f : B∗ → B∗, that is, from strings over B to strings over B. Functions with unbounded domains can be used to identify languages. A language L over the alphabet A is uniquely determined by a characteristic function f : A∗ → B with the property that L = {x | x ∈ A∗ such that f(x) = 1}. This statement means that L is the set of strings x in A∗ for which f on them, namely f(x), has value 1. We often restrict a function f : B∗ → B∗ to input strings of length n, n arbitrary. The domain of such a function is Bn. Its codomain consists of those strings into which strings of length n map. This set may contain strings of many lengths. It is often convenient to map strings of length n to strings of a fixed length containing the same information. This can be done as follows. Let h(n) be the length of a longest string that is the value of an input string of length n. Encode letters in B by repeating them (replace 0 by 00 and 1 by 11) and then add as a prefix as many instances of 01 as necessary to insure that each string in the codomain of fn has 2h(n) characters. For example, if h(4) = 3 and f(0110) = 10, encode the value 10 as 011100. This encoding provides a function fn : Bn → B2h(n) containing all the information that is in the original version of fn.