5
$\begingroup$

I was coding up some bounds propagation in some constraint satisfaction code I was playing with and decided to see if Mathematica could simplify an expression involving Min and Max. I extracted the essence of what it seemed not to be able to do.

For example:

FullSimplify[Max[a, Max[b, c]]]

gives what I expect:

Max[a, b, c]

But

FullSimplify[Max[a, Max[b + z, c + z] - z]]

doesn't:

Max[a, -z + Max[b + z, c + z]]

Often though Mathematica knows more than me. Am I missing something here?

$\endgroup$
2
  • $\begingroup$ Curious: Max[a, FullSimplify[Max[b + z, c + z] - z]] works. $\endgroup$ Mar 21 '18 at 18:49
  • 2
    $\begingroup$ FullSimplify[Max[b + z, c + z] - z] yields a Piecewise expression, not Max[b,c] as you might expect. Suppose that has something to do with it. $\endgroup$
    – george2079
    Mar 21 '18 at 19:01
1
$\begingroup$

IMO, the problem is that there is no built-in transformation like the one the OP seems be to thinking of. We can try adding it, and the desired result occurs:

Simplify[Max[a, Max[b + z, c + z] - z], 
 TransformationFunctions -> {Automatic, 
   Replace[#, HoldPattern[Max[args__] + b_] :> Max @@ ({args} + b)] &}]

(*  Max[a, b, c]  *)

If we consider the domain of Max, which includes ±Infinity in addition to the real numbers, then the above result is only generically correct, which may explain why the desired result takes some work to obtain:

Max[a, Max[b + z, c + z] - z] /. {a -> 1, b -> -Infinity, c -> 10, z -> Infinity}
(*  Infinity::indet: Indeterminate expression warning  *)
(*  Out[]= Indeterminate  *)

Max[a, b, c] /. {a -> 1, b -> -Infinity, c -> 10, z -> Infinity}
(*  Out[]= 10  *)

Nonetheless, even if you exclude infinities, the needed transformation does not seem to exist:

FullSimplify[Max[a, Max[b + z, c + z] - z], Thread[-∞ < {a, b, c, z} < ∞]]
(*  Max[a, -z + Max[b + z, c + z]]  *)
$\endgroup$
1
  • $\begingroup$ That's very interesting. Thank you for this. $\endgroup$ May 22 '18 at 14:21
0
$\begingroup$

Use PiecewiseExpand

Simplify[Max[a, Max[b + z, c + z] - z]] // PiecewiseExpand

enter image description here

Max[a, Simplify[Max[b + z, c + z] - z]] // PiecewiseExpand

enter image description here

% == %%

(* True *)
$\endgroup$
2
  • $\begingroup$ Well that doesn't really enlighten me any. I tried FindInstance[ Max[a, Max[b + z, c + z] - z] != Max[a, b, c], {a, b, c, z}] and it found no instances. So I am not missing something. $\endgroup$ Mar 21 '18 at 22:10
  • $\begingroup$ interesting, ((a - b >= 0 && b - c >= 0) || (b - c < 0 && a - c >= 0)) should reduce to a>=b&&a>=c which would make the equivalence to Max[a,b,c] more clear. $\endgroup$
    – george2079
    Mar 21 '18 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.