Function Repository Resource:

Mediant

Source Notebook

Compute the mediant of a list of non-negative rationals

Contributed by: William Gosper (with additional contributions by the Wolfram Function Repository Team)

ResourceFunction["Mediant"][{r1,r2,}]

gives the sum of the numerators of the ri divided by the sum of their denominators.

Details

ResourceFunction["Mediant"] will only evaluate if the input is a list of non-negative rational numbers (this includes integers).
The mediant of a list of positive rationals will always be between the smallest and the largest in the list.

Examples

Basic Examples (1) 

Take the mediant of a pair of fractions:

In[1]:=
ResourceFunction["Mediant"][{1/2, 3/4}]
Out[1]=

Properties and Relations (2) 

Create a list of pseudorandom positive rationals:

In[2]:=
rats = RandomInteger[{1, 10}, 20]/RandomInteger[{1, 10}, 20]
Out[2]=

Take the mediant:

In[3]:=
med = ResourceFunction["Mediant"][rats]
Out[3]=

Check that the mediant lies between the smallest and largest:

In[4]:=
Between[med, MinMax[rats]]
Out[4]=

In a Farey sequence, the kth element is the mediant of the (k-1)th and (k+1)th elements:

In[5]:=
rats = FareySequence[9]
Out[5]=
In[6]:=
With[{k = 7}, rats[[k]] == ResourceFunction["Mediant"][rats[[{k - 1, k + 1}]]]]
Out[6]=

The value of the Minkowski question mark function at the mediant can be expressed in terms of the values at the Farey neighbors:

In[7]:=
With[{k = 11},
 MinkowskiQuestionMark[
   ResourceFunction["Mediant"][rats[[{k - 1, k + 1}]]]] == 1/2 (MinkowskiQuestionMark[rats[[k - 1]]] + MinkowskiQuestionMark[rats[[k + 1]]])]
Out[7]=

Possible Issues (1) 

Mediant will not work with numbers that are not explicitly non-negative integers or rationals:

In[8]:=
ResourceFunction["Mediant"][{1/2, -3/4}]
Out[8]=

Version History

  • 1.1.0 – 24 August 2021
  • 1.0.0 – 03 April 2020

Related Resources

License Information