# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

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"][ computes the conditions under which, for a given ordering operator | |

ResourceFunction["GenerateOrderingConditions"][ assumes that the values of |

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 |

Order three symbolic expressions involving the variables *a* and *b*:

In[1]:= |

In[2]:= |

Out[2]= |

The expressions can contain constants:

In[3]:= |

Out[3]= |

Restrict the domain of permissible solutions:

In[4]:= |

Out[4]= |

Determine the conditions under which *a*−*b* will lie in the middle of the two other values:

In[5]:= |

In[6]:= |

Out[6]= |

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[7]:= |

Out[7]= |

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[8]:= |

In[9]:= |

Out[9]= |

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

In[10]:= |

In[11]:= |

Out[11]= |

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

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

Any arbitrary expression can be used as a "KeyFunction":

In[14]:= |

Out[14]= |

The default value for "KeyFunction" is Identity:

In[15]:= |

Out[15]= |

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

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

Place additional constraints on the expressions to be sorted:

In[18]:= |

Out[18]= |

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

The additional constraints can be geometric:

In[21]:= |

Out[21]= |

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

In[22]:= |

Out[22]= |

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

In[23]:= |

Out[23]= |

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[24]:= |

Out[24]= |

The Quartics option works (as does Cubics):

In[25]:= |

Out[25]= |

The WorkingPrecision option can be used:

In[26]:= |

Out[26]= |

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

In[27]:= |

In[28]:= |

Out[28]= |

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[29]:= |

In[30]:= |

Out[30]= |

Plot the corresponding region:

In[31]:= |

Out[31]= |

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

In[32]:= |

Out[32]= |

Plot the resulting region:

In[33]:= |

Out[33]= |

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

In[34]:= |

Out[34]= |

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[35]:= |

Out[35]= |

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

In[36]:= |

Out[36]= |

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[37]:= |

In[38]:= |

Out[38]= |

Plot the regions of *x* and *y* for which each candidate becomes President and Vice President:

In[39]:= |

In[40]:= |

Out[40]= |

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[41]:= |

Out[41]= |

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

This work is licensed under a Creative Commons Attribution 4.0 International License