Build a balanced comparison tournament, retaining the record of each value's direct defeats. A record stores a key and a list of records that it directly defeated:There is one key comparison at each merge. Because is a set, all keys are distinct, so the greater winner is unambiguous. Retaining the losing record also retains its own earlier comparison history; it does not merely retain the losing root's value.
tournament(S):
if |S| = 1:
return Node(the element of S, [])
split S into equally sized L and R
a = tournament(L)
b = tournament(R)
if a.key < b.key:
exchange a and b
prepend b to a.losers
return aLet the returned root have value . DefineThe second-largest value can only lose to , so it occurs among those direct losers. This proves the required partition and the exclusion of the second-largest value from the third part. For , the winner participates in exactly merges, so . The other part can be materialized by marking the original element identities in this list and scanning the original inputs, using additional operations without more comparisons between keys.
Because The lower type bound gives , so stored output values can be widened into
Set is invariant in the specified Scala library, even returning Set[U] would place the class's covariant type parameter in an invariant position. Introduce a fresh widened type for each lifting.class CoPartialFnExt[T,+U](data: List[(T,U)])
extends CoPartialFn[T,U](data) {
def forwardLift[V >: U](s: Set[T]): Set[V] = {
val ys: List[V] = this.data.collect {
case (x,y) if s.contains(x) => y
}
ys.toSet
}
def backwardLift[V >: U](s: Set[V]): Set[T] =
this.data.collect {
case (x,y) if s.contains(y) => x
}.toSet
}List[V] or passed to s.contains. Both exposed Set types use invariant method type parameters, not the class's U. Calling forwardLift[U] or backwardLift[U] when the concrete output type is known recovers the exact output universe; a broader admissible universe is also safe.For a partial function, the forward formula is understood only for inputs in its domain of a function. The implementations therefore computeThe conversion to a set removes repeated images. Inputs not in the domain of a function contribute nothing to either lifting.
Fix one distinguished element of the -element set. Every partition of a set into blocks belongs to exactly one of two cases. If is a block, removing it leaves an -block partition of a set of the other elements, giving possibilities. Otherwise remove from its block; that block remains nonempty, so the result has blocks. Conversely choose any of the such partitions and insert in any one of its blocks. This gives possibilities.
These cases are disjoint and exhaustive, proving the Stirling numbers of the second kind recurrenceUse , for , and for ; these conventions include the boundary cases and .
Count pairs of subsets of an -element candidate set with , , and . Choosing the whole team first and then the special-role players gives . Alternatively choose first, then choose the other players from the candidates outside , giving . Each construction specifies the same pair uniquely. Thus double counting proves
Suppose is the greatest lower bound of the set of all upper bounds of . Every satisfies for every , so each such is a lower bound of . Since is the greatest of those lower bounds, for every . Thus itself is an upper bound of , meaning .
Also , being a lower bound of , satisfies for every . It is therefore an upper bound of below every other upper bound, which proves . The argument also covers empty or whenever the assumed greatest lower bound exists.
Using set difference as intersection with a complement of a set, then De Morgan's laws and distribution, givesFor the third equality, expand the two set unions: the terms and are absorbed by , and . This proves the required identity entirely by set algebra.
By definition the symmetric difference is . Put and . Distribution of set intersection over set union givesFor disjoint sets, set difference removes nothing, so . ConsequentlyHere the second equality combines with ; the last uses .
Write and . Partition an -element set into distinguished pairs, and let interchange the two elements of every pair. It induces an involution on the -element subsets. Every nonfixed subset is paired with its distinct image, so nonfixed subsets contribute an even number to the binomial coefficient .
For a node tuple , write for its identifier. A predicate that is true exactly when identifiers repeat isThe inequality excludes choosing the same tuple twice. The set cannot contain two copies of an identical quadruple, but it can contain distinct quadruples with equal first component and different information or successors. The negation is the usual identifier-uniqueness representation invariant, namely .
A trie node needs a terminal flag as well as its children: a stored word can also be the prefix of a longer stored word.Index zero denotes
TYPE Trie = POINTER TO Node;
Node = RECORD
terminal: BOOLEAN;
child: ARRAY 26 OF Trie
END;a, index 25 denotes z; null pointers denote absent branches. The set represented by a nonnull node consists of the empty string if terminal is true, together with every child's words prefixed by that child's letter. Represent the empty set by NIL. The singleton containing the empty string instead has a terminal root and no children.The declarations alone do not force a unique representation. A nonterminal leaf, or a whole branch without terminal descendants, contributes no word. To obtain uniqueness up to pointer addresses, impose a representation invariant: the structure is a finite rooted tree, and each allocated node lies on a path to a terminal node. Then precisely the prefixes of stored words exist, all flags are determined, and the empty set has only the
NIL representation. The insertion procedures below preserve this invariant when starting with such a trie.Allocate nodes only as required, explicitly initializing every field:Here
PROCEDURE Make(VAR t: Trie);
VAR c: INTEGER;
BEGIN
NEW(t); t.terminal := FALSE; c := 0;
WHILE c < 26 DO t.child[c] := NIL; c := c+1 END
END Make;
PROCEDURE AddTail(VAR t: Trie; s: ARRAY OF CHAR; i: INTEGER);
BEGIN
IF t = NIL THEN Make(t) END;
IF s[i] = 0X THEN
t.terminal := TRUE
ELSE
AddTail(t.child[Index(s[i])], s, i+1)
END
END AddTail;
PROCEDURE Add(VAR t: Trie; s: ARRAY OF CHAR);
BEGIN
AddTail(t, s, 0)
END Add;0X is the zero character, and s must contain its terminator within its array bounds. Make establishes that the first c child fields are NIL as its loop invariant. Passing t by reference lets the base allocation replace a missing root or child pointer.For correctness, use induction on the number of characters before the terminator. At length zero, setting
terminal adds exactly the empty suffix. Otherwise the chosen child stores exactly words with the required next letter, and the induction hypothesis adds the remaining suffix while preserving all other words. Thus the resulting set is the old set union the supplied word, ignoring case. Repeated insertion changes no word membership. A newly allocated path reaches the newly terminal node, preserving the canonical representation invariant after the procedure finishes. The running time is for a word of length , using call stack space without optimization.We prove both set inclusions. If , then and . Since , the latter condition forces , giving . Conversely, if , then and , so . By set extensionality, the two sets are equal. This is a double inclusion proof; the implication involving the set difference uses membership in explicitly.
True. The two operations retain complementary membership information. For , equality of the intersections makes equivalent to . For , equality of the unions makes equivalent to . These cases exhaust every possible element. Set extensionality therefore gives . Equivalently, reconstruct either set fromSubstituting the two given equalities into this expression gives .
False. Take the sets , and . Both intersections with are empty, although . Intersecting with loses information about membership outside .
False. With the sets , and , both set differences are empty but . Removing loses the distinction between their memberships inside .
Substituting cancels both the cubic and linear terms, leaving for every real . Thus the constrained maximum and minimum are both zero, attained everywhere on the constraint line. The feasible set is unbounded, but the restricted function is constant; compactness is not needed here.
subs :: Tree a -> [Tree a]
subs t@(One _) = [t]
subs t@(Two l r) = t : (subs l ++ subs r)This is a preorder traversal of subtree occurrences. Equal-valued occurrences are retained: the answer is a list, not a deduplicated set. Every occurrence is either the root or lies in exactly one child, which proves completeness by structural induction.
A derangement of a finite set is a permutation with no fixed point: for every . Thus every element is moved, although the permutation remains a bijection.
The displayed relation is not a partial order on the printed . Since the empty set belongs to , vacuous truth makeshold for every finite , including nonempty . This violates the defining condition of an antisymmetric relation. It also violates transitivity: holds, but . Consequently the usual unique-maximum and unique-least upper bound terminology for a partially ordered set does not apply as claimed.
The available inputs still determine what happens if one applies the formulas in (b) literally to this relation:
| Family | Elements satisfying the maximum formula | Elements satisfying the least-upper-bound formula |
|---|---|---|
| None | ||
| and | and | |
| None | and |
For , no nonempty finite set can lie above all triples of arbitrarily large numbers, while does so vacuously. Thus is its sole literal upper bound, but is not a member of . For each of the two bounded families, the literal upper bounds are and all nonempty finite sets whose elements are at least . Among these, exactly and lie below every such upper bound. Both belong to , but neither belongs to its three-element subfamily.
For comparison, a natural correction is to retain the given rule for nonempty sets and declare to be a bottom element: no nonempty set is then below . Under this explicitly corrected partial order, has neither a maximum nor a least upper bound; has maximum and least upper bound ; and has no maximum but has least upper bound . A nonempty upper bound must have every element at least as large as every element of the bounded family. These corrected answers are conditional on the stated repair, not answers obtained by silently excluding the empty set from the source.