# Speculation chained comparison optimization (possibly with outlining)

**URL:** <https://discourse.julialang.org/t/speculation-chained-comparison-optimization-possibly-with-outlining/1354>\
**Category:** Offtopic\
**Created:** [January 8, 2017, 5:09pm UTC](https://discourse.julialang.org/t/speculation-chained-comparison-optimization-possibly-with-outlining/1354 "2017-01-08T17:09:06Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 8, 2017, 6:32pm UTC](https://discourse.julialang.org/t/speculation-chained-comparison-optimization-possibly-with-outlining/1354/6 "2017-01-08T18:32:49Z")

</div>

> [@A != b != c](https://discourse.julialang.org/t/a-b-c/1347/16):
>
> The Julia implementation could check a \< c first (and probably a better strategy for speed).

Nothing prevents you from testing the condition

```julia
1 < -3 < 4

```

in this case there is no performance gain, on the contrary you’ll have performed one extra test.

In addition, the parser should know in advance that the operator `<` is transitive, it can’t assume transitivity in all cases such this. Consider the case `a < b > c`, the parser should know that `<` and `>` are opposite, so transitivity can’t be assumed there. It won’t work with arbitrary comparison operators. Is all this worth?

---

_[View the full topic](https://discourse.julialang.org/t/speculation-chained-comparison-optimization-possibly-with-outlining/1354)._
