Function Repository Resource:

# GenerateOrderingConditions

Generate the conditions under which a list of symbolic expressions has a particular ordering or set of orderings with respect to an operation

Contributed by: Seth J. Chandler
 ResourceFunction["GenerateOrderingConditions"][op,exprs,vars] computes the conditions under which, for a given ordering operator op, each possible ordering of the symbolic expressions in exprs would occur, assuming that vars is the list of variables in exprs. ResourceFunction["GenerateOrderingConditions"][op,exprs,vars,dom] assumes that the values of vars are confined to the domain dom.

## Details and Options

By default, the function produces an Association in which each key is an ordering of the symbolic expressions exprs and the values are the conditions under which that ordering would exist.
The op argument is likely to be a function such as Greater, Less or other function with arity of 2 or more that yields True or False when its arguments are real values.
The arguments of the function after the initial op argument are precisely the same as those available for Reduce, though additional options are supported.
If the list contains duplicate expressions and the operator is Greater, Less or others where ties are prohibited, all values produced by the function will be False.
ResourceFunction["GenerateOrderingConditions"] has the same options as Reduce, with the following additions:
 "AdditionalConstraints" {} constraints on permissible values of the variables "KeyFunction" Identity a function to map over the keys of the output Association "Pattern" _ specification of which orderings of the expressions will be considered "PatternInterpreter" (Function[explist,Function[pat,pat]]) how to interpret the value of the "Pattern" option

## Examples

### Basic Examples (1)

Order three symbolic expressions involving the variables a and b:

 In:= In:= Out= ### Scope (2)

The expressions can contain constants:

 In:= Out= Restrict the domain of permissible solutions:

 In:= Out= ### Options (10)

#### Pattern (2)

Determine the conditions under which ab will lie in the middle of the two other values:

 In:= In:= Out= Determine the conditions under which the ordering of a four-element list with respect to an operation will have its fourth member first and its second member third:

 In:= Out= #### PatternInterpreter (2)

By setting the "PatternRepresentation" option, you can change the interpretation of the value of the "Pattern" option. For a value f taken by this option, and a value explist of the expressions to be sorted, the value of the "Pattern" option pat is interpreted as f[explist][pat]. Interpret the value of the "Pattern" option as indices into the list of expressions:

 In:= In:= Out= Use integer indices to represent a desired ordering but also permit blank patterns where one does not care about the exact ordering:

 In:= In:= Out= #### KeyFunction (2)

Represent the keys not as the expressions themselves but by indices into the original expression list:

 In:= Out= In:= Out= Any arbitrary expression can be used as a "KeyFunction":

 In:= Out= The default value for "KeyFunction" is Identity:

 In:= Out= One can combine the "KeyFunction" option with the "Pattern" and "PatternInterpretation" functions:

 In:= Out= In:= Out= Place additional constraints on the expressions to be sorted:

 In:= Out= In:= Out= In:= Out= The additional constraints can be geometric:

 In:= Out= The additional constraints can result from the computation of an ImplicitRegion:

 In:= Out= The additional constraints can result from the computation of a ParametricRegion:

 In:= Out= All the options for Reduce are also supported, including user-specified generated parameters and display of full cubic and quartic expressions instead of root objects. The GeneratedParameters option works:

 In:= Out= The Quartics option works (as does Cubics):

 In:= Out= The WorkingPrecision option can be used:

 In:= Out= ### Applications (2)

Show conditions under which a-b will have the smallest value among {a+b,ab,ab}, but also requiring a+b<3:

 In:= In:= Out= In a three-party race, the first candidate has 20 votes, the second candidate has 25 votes, and the third candidate has 27 votes. It is estimated, however, that only 70% of the votes have been counted. Compute the conditions under which candidate 1 will end up with the most votes:

 In:= In:= Out= Plot the corresponding region:

 In:= Out= Do the same computation but assume that to avoid a runoff election, candidate 1 must get more than 50% of the total votes:

 In:= Out= Plot the resulting region:

 In:= Out= ### Possible Issues (3)

The "Modulus" option cannot be used if the op argument generates an inequality:

 In:=  Out= As the length of the expression list grows or the length of the vars argument grows, the time needed to do the computations can grow significantly:

 In:= Out= If Reduce cannot determine the order of the expressions, the computation can take a long time:

 In:= Out= ### Neat Examples (3)

Under the original Article II of the United States Constitution and prior to the enactment of the Twelfth Amendment, the presidential candidate with the most votes in the electoral college would become the President of the United States and the candidate with the second-most votes would become the Vice President, even if the President and Vice President had serious disagreements. Suppose the electoral college votes of four candidates subject to that voting system depend on two parameters, x and y. Compute the conditions for each ordering of the four candidates:

 In:= In:= Out= Plot the regions of x and y for which each candidate becomes President and Vice President:

 In:= In:= Out= Compute the probability that each candidate will become President and Vice President, assuming that x and y are drawn from a multivariate normal distribution:

 In:= Out= Seth J. Chandler

## Version History

• 2.0.0 – 09 November 2020
• 1.0.0 – 23 October 2020