Skip to main content
shorten the sum in the criterion
Source Link
flinty
  • 25.9k
  • 2
  • 22
  • 92
findit[L_, f_] :=
 (* select pairs of subsets in the powerset Subsets[L] that satisfy the criterion *)
 ResourceFunction["SelectSubsets"][
  Subsets[L], {2}, 
  f[#[[1]]]Total[f +/@ f[#[[2]]]#] > f[Union @@ #] + f[Intersection @@ #] &
  ]
findit[{1, 2, 3}, Median]
(* result: {{{1,2},{1,3}}} *)

(* check it works *)
Median[{1, 2}] + Median[{1, 3}] > 
 Median[Union[{1, 2}, {1, 3}]] + Median[Intersection[{1, 2}, {1, 3}]]
(* result: True *)
findit[L_, f_] :=
 (* select pairs of subsets in the powerset Subsets[L] that satisfy the criterion *)
 ResourceFunction["SelectSubsets"][
  Subsets[L], {2}, 
  f[#[[1]]] + f[#[[2]]] > f[Union @@ #] + f[Intersection @@ #] &
  ]
findit[{1, 2, 3}, Median]
(* result: {{{1,2},{1,3}}} *)

(* check it works *)
Median[{1, 2}] + Median[{1, 3}] > 
 Median[Union[{1, 2}, {1, 3}]] + Median[Intersection[{1, 2}, {1, 3}]]
(* result: True *)
findit[L_, f_] :=
 (* select pairs of subsets in the powerset Subsets[L] that satisfy the criterion *)
 ResourceFunction["SelectSubsets"][
  Subsets[L], {2}, 
  Total[f /@ #] > f[Union @@ #] + f[Intersection @@ #] &
  ]
findit[{1, 2, 3}, Median]
(* result: {{{1,2},{1,3}}} *)

(* check it works *)
Median[{1, 2}] + Median[{1, 3}] > 
 Median[Union[{1, 2}, {1, 3}]] + Median[Intersection[{1, 2}, {1, 3}]]
(* result: True *)
Source Link
flinty
  • 25.9k
  • 2
  • 22
  • 92

findit[L_, f_] :=
 (* select pairs of subsets in the powerset Subsets[L] that satisfy the criterion *)
 ResourceFunction["SelectSubsets"][
  Subsets[L], {2}, 
  f[#[[1]]] + f[#[[2]]] > f[Union @@ #] + f[Intersection @@ #] &
  ]
findit[{1, 2, 3}, Median]
(* result: {{{1,2},{1,3}}} *)

(* check it works *)
Median[{1, 2}] + Median[{1, 3}] > 
 Median[Union[{1, 2}, {1, 3}]] + Median[Intersection[{1, 2}, {1, 3}]]
(* result: True *)