# Max() bug?

**URL:** https://discourse.julialang.org/t/max-bug/48070
**Category:** New to Julia
**Created:** [October 9, 2020, 10:19pm UTC](https://discourse.julialang.org/t/max-bug/48070 "2020-10-09T22:19:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)
#### Post date: [October 9, 2020, 10:19pm UTC](https://discourse.julialang.org/t/max-bug/48070/1 "2020-10-09T22:19:08Z")

</div>

```julia
julia> a=[1,2,3];
julia> b=[10,-Inf,9];
julia> c=[-30,5,2];
julia> max(a,b,c)
3-element Array{Float64,1}:
  10.0
 -Inf
   9.0
julia> max.(a,b,c)
3-element Array{Float64,1}:
 10.0
  5.0
  9.0

```

`max.(a,b,c)` is correct. Why is it not equal to `max(a,b,c)` for the second element?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [October 9, 2020, 10:32pm UTC](https://discourse.julialang.org/t/max-bug/48070/2 "2020-10-09T22:32:14Z")

</div>

`max()` returns the maximum of its arguments. That is, `max(a, b, c)` returns whichever of `a`, `b` or `c` is greatest. It then follows that whatever is returned by `max(a, b, c)` must be one of `a`, `b`, or `c`. In your case, the answer is `b`, which is exactly what is returned.

`max.(a, b, c)` is the elementwise maximum of the three inputs, so it gives a different answer.

---

<div class="post-metadata">

### Author: ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)
#### Post date: [October 9, 2020, 10:35pm UTC](https://discourse.julialang.org/t/max-bug/48070/3 "2020-10-09T22:35:30Z")

</div>

But b is neither bigger nor smaller than the vector a.  
What sort of vector order is being assumed?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [October 9, 2020, 10:37pm UTC](https://discourse.julialang.org/t/max-bug/48070/4 "2020-10-09T22:37:56Z")

</div>

Vectors are compared in lexicographic order, so `b` is greatest because the first element of `b` is greater than the first elements of `a` and `c`.

---

<div class="post-metadata">

### Author: ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)
#### Post date: [October 9, 2020, 10:44pm UTC](https://discourse.julialang.org/t/max-bug/48070/5 "2020-10-09T22:44:10Z")

</div>

Thanks.  
Can anyone refer me to where in the docs it is explained that Lexicographic order is the default for max?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [October 10, 2020, 2:41pm UTC](https://discourse.julialang.org/t/max-bug/48070/6 "2020-10-10T14:41:21Z")

</div>

This has nothing to do with `max` itself–it just uses the result of the `<` function. The lexicographic ordering comes from the definition of `<` (which by default falls back to the function `isless`) for abstract vectors. I don’t have a link to the relevant part of the documentation handy, but that’s where you’d want to look.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [October 11, 2020, 9:28am UTC](https://discourse.julialang.org/t/max-bug/48070/7 "2020-10-11T09:28:02Z")

</div>

`isless(::Tuple, ::Tuple)` mentions lexicographic ordering, but the method for vectors does not have a docstring, so I made a tiny PR adding it:

[https://github.com/JuliaLang/julia/pull/37986](https://github.com/JuliaLang/julia/pull/37986)
