# Interval calculations in wolfram mathematica

If x = Interval[-100,100], then obviously x^2 + x = Interval[-0.25,10100], because as we know, x^2+x > -0.25. But Mathematica gives me:

x^2 + x /. x -> Interval[{-100, 100}]
(* Interval[{-100, 10100}] *)


How can I automatically get correct interval Interval[-0.25,10100] from Mathematica?

• ref / Interval / Possible Issues – Kuba Nov 3 '15 at 14:08

A different way to go that captures more information than merely the intervals is:

result = TransformedDistribution[x^2 + x, Distributed[x, UniformDistribution[{-100, 100}]] ];
Plot[Evaluate[PDF[result, x]], {x, -1, 1}]
(* Discover that the likelihood of various results is not uniform. *)
Interval[{
Minimize[{x, #}, x, Reals][[1]],
Maximize[{x, #}, x, Reals][[1]]
} &[Reduce[PDF[result, x] > 0, x]]]


We can wrap this in a function (includes streamlining from @ybeltukov ):

dependentInterval[func_, marginVar_, varDef___] := Interval[{
MinValue[{marginVar, #}, marginVar, Reals],
MaxValue[{marginVar, #}, marginVar, Reals]
} &[Reduce[
PDF[TransformedDistribution[func, Sequence /@ varDef],
marginVar] > 0, marginVar]
]]

dependentInterval[x^2 + x, x, Distributed[x, UniformDistribution[{-100, 100}]] ]
(* Interval[{-(1/4), 10100}] *)

• makes sence, thanx! – stiv Nov 4 '15 at 1:40
• @ybeltukov : You're right. (Ack. How did this post make it to the top answer?...) – Eric Towers Nov 5 '15 at 20:12

A possible approach for dependent intervals:

Interval@*Through@{MinValue, MaxValue}[u + u^2, {u} ∈ Interval[{-100, 100}]]
(* Interval[{-(1/4), 10100}] *)

• That's a new one, what does @* mean? – Jason B. Nov 3 '15 at 14:35
• Is it really impossible to make this searchable in the documentation? Typing ?@@ works, but ?@@@ or ?@ or ?@* gives nothing – Jason B. Nov 3 '15 at 14:38
• I'd be very thankfull if author will explain this strange syntax with @* – stiv Nov 3 '15 at 14:52
• It's Composition, as in Composition[f, g, h][x] means f[g[h[x]]]. What I don't understand is why it is needed - f @ g @ h @ x seems to give the same answer as f @* g @* h @ x – Jason B. Nov 3 '15 at 14:58
• @JasonB Actually ? and @ acts weird together. Sometimes @ is any number of lowercase characters and sometimes not. – ybeltukov Nov 3 '15 at 16:34
u = Interval[{-100, 100}]


According to ref / Interval / Possible Issues

Intervals are always assumed independent

so u + u^2 is something like v + u ^ 2 -> Interval[{-100, 100}] + Interval[{0, 10000}].

What can also be surprising, is the fact it is different from u + u * u which we can think of as v + u * w.

I the first example u^2 is at least 0 but in the second u can be -100 while w is 100 so the answer is: Interval[{-100, 100}] + Interval[{-10000, 10000}] -> Interval[{-10100, 10000}]

• How can I automatically get correct interval Interval[-0.25,10100] from Mathematica? – stiv Nov 3 '15 at 14:27
• @stiv good point, I should answer the question :) – Kuba Nov 3 '15 at 14:33