-1

I am a complete beginner to SageMath. I was wondering how I could recreate the maximum-minimum identity using it. Any idea?

Cesare
  • 332
  • What do you mean by "recreate"? Do you want to write some code that takes a list of numbers and calculates the max (or min) in both ways, so you can verify they are indeed equal? – Chris Grossack Jun 25 '20 at 06:13
  • 1
    I would like a system that given the inputs $x_2, \dots, x_N$ gives the whole expansion for max and for min. – Cesare Jun 25 '20 at 06:38
  • Does that mean to calculate the minimum and maximum using the max-min-identity? Something like, def mymax(x): return sum([min(comb)*(-1)^(len(comb)+1) for comb in Combinations(x) if comb]) and def mymin(x): return sum([max(comb)*(-1)^(len(comb)+1) for comb in Combinations(x) if comb])? Or are you looking for a symbolic expansion? – rickhg12hs Jun 26 '20 at 12:35
  • I am looking for a symbolic expantion, where I can then impose condition. But I have no idea whether this is possible in Sage. I think it might be possible in Mathematica. – Cesare Jun 26 '20 at 16:12

1 Answers1

0

Let us work on the first maximum-minimum formula :

$${\displaystyle {\max\{x_{1},x_{2},\ldots ,x_{n}\}=\\ \sum _{i=1}^{n}x_{i}-\sum _{i<j}\min\{x_{i},x_{j}\}+\sum _{i<j<k}\min\{x_{i},x_{j},x_{k}\}-\cdots \\\qquad \cdots +\left(-1\right)^{n+1}\min\{x_{1},x_{2},\ldots ,x_{n}\}}}\tag{1}$$

Here is a SAGE implementation of the computation of the RHS of (1), taking advantage of the fact that "Combination(x)" outputs the list of subsets of $x$ by increasing sizes:

 x=[5,2,8,7]
 C=Combinations(x)
 C= [C[i] for i in range(1,2^len(x))]; # removal of the (initial) void set
 show(C)
 sig=-1; # signum
 su=0; # sum in the RHS
 L=0; # length of the current subset
 for comb in C:
    if len(comb)>L:
       sig=-sig;
       L+=1;
    su+=sig*min(comb)
 print(su)

In the present case, the output is $8$, the "max" element of list $x$.

For the second case, just replace "min" by "max".

Jean Marie
  • 88,997