On the nonempty set take the empty binary relation . There are no triples for which holds. The defining implication is therefore true for every triple by vacuous truth, making a Euclidean relation.
But is false, so is not a reflexive relation and hence is not an equivalence relation:
Take the natural numbers including zero with their usual total order:
A nonempty subset with an upper bound is contained in the finite set . It therefore has a greatest element, which is its least upper bound. The empty subset has least upper bound . Thus is a bounded-complete partially ordered set.
But is a directed set, since is above any two members. It has no upper bound in : for any proposed bound , the member is larger. It therefore has no least upper bound. Hence
A matching mother or father field identifies a child. In Haskell:
children :: Database -> Person -> [Person]
children db p = unique [baby | (baby,mother,father) <- db,
                              mother == p || father == p]
Duplicate removal handles repeated certificates and children recorded in more than one matching row. Thus
The displayed set describes membership; the implementation returns its entries as a list in first certificate order.
Extract the two recorded parents from every matching certificate, and use duplicate removal so that repeated certificates do not repeat an individual. This helper is shared by the remaining Haskell definitions:
unique :: Eq a => [a] -> [a]
unique [] = []
unique (x:xs) = x : unique [y | y <- xs, y /= x]

parents :: Database -> Person -> [Person]
parents db p = unique [q | (baby,mother,father) <- db,
                          baby == p, q <- [mother,father]]
A person need not have a certificate of their own to appear in the output: a parental field is already evidence of the relationship. The resulting list preserves first occurrence order, with mother before father in each certificate. Its set of entries is
The image of a linear map and kernel of a linear map are
A linear map sends zero to zero, since . Thus both displayed sets contain zero. If and belong to the image of a linear map, then for any real scalars ,
If belong to the kernel of a linear map, then
so . Containing zero and being closed under linear combinations is the vector subspace criterion. Hence the image of a linear map is a vector subspace of , and the kernel of a linear map is a vector subspace of .
Use the two-chain noncontinuous complete partial order
where and , with no comparisons between the two interiors. In this solution denotes the least upper bound printed as in the question.[ref]
Every nonempty directed set containing has least upper bound . A directed set omitting cannot contain both an and a , because their only common upper bound in is , which would have to belong to that directed set. It therefore lies in one chain, possibly with . If its indices are bounded it has a greatest element, which is its least upper bound; if they are unbounded its least upper bound is . Thus is a directed-complete partial order.
No element other than is way-below . For , the directed set has least upper bound , but none of its members is above . Interchanging the two chains excludes every . Either chain excludes itself. On the other hand, : every directed set whose least upper bound is above is nonempty, and any member is above . Hence
So is not a continuous directed-complete partial order.
There is a small convention issue in the printed definitions. Our usual directed set is nonempty, but the question's pairwise condition also allows the empty set. Taken literally, the empty set has least upper bound , and the preceding example and failure of continuity still work. Under this literal convention , because the empty set supplies no witness. We retain this qualification in the next parts.
Figure 1.
Two branches with a common supremum, compared with continuous approximation in the unit interval
. Details.
The continuous nonalgebraic unit interval is
Every nonempty directed set has a least upper bound by completeness of the real numbers, and that least upper bound lies in . Thus this is a directed-complete partial order.
For , we have . Indeed, if and no were at least , then would be an upper bound for , implying , a contradiction. If , the singleton directed set excludes . If , the increasing sequence , , has least upper bound and has no member at least , so .
Under the usual nonempty convention, . Therefore the elements way-below form , and those way-below form . These are directed sets with least upper bounds and , respectively, proving that is a continuous directed-complete partial order. Its only compact element is . For any , the compact elements below have least upper bound , rather than , so it is not an algebraic partially ordered set.
Under the literal empty-set convention of the paper, as well. The elements way-below zero then form the empty set, which is directed in that convention and has least upper bound zero. There are no compact elements, and their empty set still fails to approximate any positive . Thus both conventions give the same requested classification:
The requested examples are binary relations on sets, rather than partially ordered sets: a partially ordered set necessarily has all three properties. This corrects the wording of the source.[ref]
For an antisymmetric relation and transitive relation that is not a reflexive relation, take and . No distinct pair relates both ways, so the antisymmetric relation condition holds. There are no composable pairs, so the transitive relation condition holds vacuously. Neither nor belongs to , so the reflexive relation condition fails.
For a reflexive relation and transitive relation that is not an antisymmetric relation, take and . All diagonal pairs and all composite pairs belong to , but and both hold with .
For a reflexive relation and antisymmetric relation that is not a transitive relation, take
All diagonal pairs are present, and no off-diagonal pair has its reverse present. However and hold while fails. Thus each pair of axioms can hold without the third.
A regular language over a finite alphabet is a formal language recognized by a deterministic finite automaton; equivalently it is described by a regular expression. A nondeterministic finite automaton accepts an input string if at least one permitted computation consumes that string and reaches an accepting state. The connection is the equivalence
Every deterministic finite automaton is a special case of a nondeterministic finite automaton. Conversely, the subset construction makes a deterministic finite automaton whose states record the set of all possible current states of a nondeterministic finite automaton. After each input symbol, update that set by taking all permitted transitions, also including any epsilon closure. A new state is accepting exactly when it contains an old accepting state. A finite state set has finitely many subsets, so this really is a deterministic finite automaton recognizing the same formal language.
A context-free grammar is a quadruple : is a finite set of nonterminal symbols, is a disjoint finite alphabet of terminal symbols, is the start symbol, and is a finite set of productions , with and . Its formal language consists of the terminal strings derivable from .
For the even-length palindromes in (b)(ii), take terminal alphabet and the context-free grammar
Every production adds identical symbols at the two ends, so every generated string is an even-length palindrome. Conversely, remove the matching outer pair of any nonempty even-length palindrome and repeat; this constructs its derivation, ending with .
For the unequal-block formal language in (b)(iv), use
After uses of , and zeros from , the resulting string is , so its zero count is larger. Every such unequal pair with occurs by choosing . Similarly generates exactly with , covering precisely . The start alternatives cover both possibilities and never equal counts. If positive exponents are required, replace the start productions by , which adds one matched pair and ensures both counts are positive.
Let be the two input lengths and suppose numeric comparisons cost constant time. The list-based set representation determines which representation invariant each answer must preserve.
For unsorted lists allowing repetition, retain every left-hand occurrence whose value appears on the right for set intersection, and use list concatenation for set union:
interR xs ys = [x | x <- xs, x `elem` ys]
unionR xs ys = xs ++ ys
The resulting lists represent exactly the desired sets; repeated entries are permitted. Membership by sequential search makes interR take time complexity in the worst case. The list concatenation in unionR costs to build its copied left spine and shares ys; fully enumerating the resulting list costs .
For unsorted, duplicate-free inputs, the same intersection keeps uniqueness, while the union retains xs and appends only right-hand elements absent from xs:
interU xs ys = [x | x <- xs, x `elem` ys]
unionU xs ys = xs ++ [y | y <- ys, not (y `elem` xs)]
Neither filtered list has internal repetitions, and the filter in unionU also excludes overlap with xs. Both operations have worst-case time complexity, customarily written when both lengths are positive. Using the original xs for each membership test avoids searching an ever-growing output.
For sorted, duplicate-free lists, compare only the two current heads:
interS [] ys = []
interS xs [] = []
interS (x:xs) (y:ys)
  | x < y = interS xs (y:ys)
  | x > y = interS (x:xs) ys
  | otherwise = x : interS xs ys

unionS [] ys = ys
unionS xs [] = xs
unionS (x:xs) (y:ys)
  | x < y = x : unionS xs (y:ys)
  | x > y = y : unionS (x:xs) ys
  | otherwise = x : unionS xs ys
When , sortedness proves that cannot occur anywhere in the right list, so it can be discarded from the set intersection or immediately emitted to the set union. The symmetric argument handles ; equal heads are consumed together. Each step consumes at least one input head, so both have worst-case time complexity. These bounds assume the sorted representation invariant is already established; sorting arbitrary inputs has its own cost.
RepresentationSet intersectionSet union, including output traversal
Unsorted, repetitions allowed
Unsorted, unique
Sorted, unique
Use De Morgan's laws to remove the complement of a set, then distribute the two unions:
The first and last intersections in the middle line are the empty set. The remaining union is precisely the collection of elements belonging to exactly one of the original sets. Therefore both expressions define the same symmetric difference:
Use the symmetric difference formula from part (b), followed by the set difference identity from part (c)(ii):
Taking both complements swaps the two ways to belong to exactly one set, leaving their union unchanged:
For finite sets, the inclusion-exclusion principle states
An element present in of the sets is counted times, which explains the alternating corrections.
There are positive integers strictly below divisible by . For the divisors , the single counts are . Their pairwise intersections correspond to divisibility by , giving . The triple intersection has elements. Therefore
A binary relation on is a subset of . Its properties are quantified over elements of :
Thus an equivalence relation is a binary relation that is simultaneously reflexive, symmetric and transitive. The equivalence class of is the set of all elements related to it:
Antisymmetry permits diagonal pairs and does not mean that a binary relation fails to be a symmetric relation.
An empty constructor and a constructor containing a label and two subtrees give a polymorphic algebraic data type:
data STree a = Empty | Node (STree a) a (STree a)
  deriving (Eq, Show)
The binary search tree invariant is at each Node left x right, together with the same invariant recursively in both subtrees. Labels are distinct because the representation is of a set. The declaration itself needs no ordering constraint; operations that compare labels require Ord a in their type signatures.
Follow the unique branch in which the new key could belong. At an equal key, keep the existing node so that duplicate insertion does not change the represented set:
insert :: Ord a => a -> STree a -> STree a
insert y Empty = Node Empty y Empty
insert y (Node left x right) =
  case compare y x of
    LT -> Node (insert y left) x right
    EQ -> Node left x right
    GT -> Node left x (insert y right)
The Haskell Ord class supplies the three-way comparison. Each visited nonempty node costs one such comparison; rebuilding a node preserves all untouched subtrees. The inserted key satisfies every comparison along its search path, so it obeys both the local and ancestor binary search tree inequalities.
For height of a binary tree , the worst search costs when it reaches the bottom. With existing nodes, a chain can require comparisons, giving a worst case of . Under the standard random-insertion model, distinct keys arrive in a uniformly random order and the expected path length is . Thus the usual average-case answer is for growing , but this expectation needs the stated distribution: an arbitrary unbalanced binary search tree has no logarithmic guarantee.
Search as for insertion. Removing a node with at most one nonempty child leaves that child in its place. With two children, use the smallest key in the right subtree as the replacement and remove that occurrence from the right subtree:
delete :: Ord a => a -> STree a -> STree a
delete _ Empty = Empty
delete y (Node left x right) =
  case compare y x of
    LT -> Node (delete y left) x right
    GT -> Node left x (delete y right)
    EQ -> join left right
  where
    -- Join two search trees with every left key below every right key.
    join :: STree a -> STree a -> STree a
    join Empty r = r
    join l Empty = l
    join l r = let (smallest, rest) = takeMin r
               in Node l smallest rest

-- Precondition: the input tree is nonempty.
takeMin :: STree a -> (a, STree a)
takeMin Empty = error "takeMin: empty tree"
takeMin (Node Empty x right) = (x, right)
takeMin (Node left x right) =
  let (smallest, rest) = takeMin left
  in (smallest, Node rest x right)
The call to takeMin occurs only after both empty cases have been excluded. Its structural recursion follows left children until it reaches the minimum label and rebuilds the path with that occurrence removed.
For a matching label and successor , all left labels are below , while every label remaining on the right is strictly above . Thus replacing by preserves the binary search tree invariant. Every other branch preserves the invariant by structural induction. The resulting set is exactly
Whether the key is absent or present, untouched subtrees can be shared. The search path followed by the successor path uses time and fresh nodes for original height of a binary tree , so the worst case is without balancing. This is persistent binary search tree deletion: the original value remains available.