<p dir="auto">It would be very useful for packages to be able to extend chained comparisons like</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="using ModelingToolkit

@variables x, y

-1 &lt; y - x^2 &lt; 1"><pre class="notranslate"><span class="pl-k">using</span> ModelingToolkit

<span class="pl-c1">@variables</span> x, y

<span class="pl-k">-</span><span class="pl-c1">1</span> <span class="pl-k">&lt;</span> y <span class="pl-k">-</span> x<span class="pl-k">^</span><span class="pl-c1">2</span> <span class="pl-k">&lt;</span> <span class="pl-c1">1</span></pre></div>
<p dir="auto">to act on their types. Currently this is not possible since chained comparisons are lowered straight to a too-low-level form:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; Meta.@lower -1 &lt; y - x^2 &lt; 1
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─ %1 = Core.apply_type(Base.Val, 2)
│   %2 = (%1)()
│   %3 = Base.literal_pow(^, x, %2)
│   %4 = y - %3
│   %5 = -1 &lt; %4
└──      goto #3 if not %5
2 ─ %7 = %4 &lt; 1
└──      return %7
3 ─      return false
))))"><pre class="notranslate">julia<span class="pl-k">&gt;</span> Meta<span class="pl-k">.</span><span class="pl-c1">@lower</span> <span class="pl-k">-</span><span class="pl-c1">1</span> <span class="pl-k">&lt;</span> y <span class="pl-k">-</span> x<span class="pl-k">^</span><span class="pl-c1">2</span> <span class="pl-k">&lt;</span> <span class="pl-c1">1</span>
:(<span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:thunk</span>, <span class="pl-c1">CodeInfo</span>(
    @ none within <span class="pl-s"><span class="pl-pds">`</span>top-level scope'</span>
<span class="pl-s">1 ─ %1 = Core.apply_type(Base.Val, 2)</span>
<span class="pl-s">│   %2 = (%1)()</span>
<span class="pl-s">│   %3 = Base.literal_pow(^, x, %2)</span>
<span class="pl-s">│   %4 = y - %3</span>
<span class="pl-s">│   %5 = -1 &lt; %4</span>
<span class="pl-s">└──      goto #3 if not %5</span>
<span class="pl-s">2 ─ %7 = %4 &lt; 1</span>
<span class="pl-s">└──      return %7</span>
<span class="pl-s">3 ─      return false</span>
<span class="pl-s">))))</span></pre></div>
<p dir="auto">The representation of sparse matrices allow for duplicates. This seems prone to errors, for instance computing the number of non-zeros entries would be incorrect.</p>
<p dir="auto">Since this is not allowed in full matrices, does it make any sense to have this be the behavior for sparse matrices?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; a = spzeros(2, 3)
2×3 SparseMatrixCSC{Float64,Int64} with 0 stored entries

julia&gt; a[[1,1,1,1,1,1],2]=1
1

julia&gt; a
2×3 SparseMatrixCSC{Float64,Int64} with 6 stored entries:
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0"><pre class="notranslate"><code class="notranslate">julia&gt; a = spzeros(2, 3)
2×3 SparseMatrixCSC{Float64,Int64} with 0 stored entries

julia&gt; a[[1,1,1,1,1,1],2]=1
1

julia&gt; a
2×3 SparseMatrixCSC{Float64,Int64} with 6 stored entries:
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0
  [1, 2]  =  1.0
</code></pre></div>