7
$\begingroup$

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?

$\endgroup$
  • 2
    $\begingroup$ ref / Interval / Possible Issues $\endgroup$ – Kuba Nov 3 '15 at 14:08
4
$\begingroup$

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}] *)
$\endgroup$
  • $\begingroup$ makes sence, thanx! $\endgroup$ – stiv Nov 4 '15 at 1:40
  • $\begingroup$ @ybeltukov : You're right. (Ack. How did this post make it to the top answer?...) $\endgroup$ – Eric Towers Nov 5 '15 at 20:12
8
$\begingroup$

A possible approach for dependent intervals:

Interval@*Through@{MinValue, MaxValue}[u + u^2, {u} ∈ Interval[{-100, 100}]]
(* Interval[{-(1/4), 10100}] *)
$\endgroup$
  • 1
    $\begingroup$ That's a new one, what does @* mean? $\endgroup$ – Jason B. Nov 3 '15 at 14:35
  • 4
    $\begingroup$ Is it really impossible to make this searchable in the documentation? Typing ?@@ works, but ?@@@ or ?@ or ?@* gives nothing $\endgroup$ – Jason B. Nov 3 '15 at 14:38
  • $\begingroup$ I'd be very thankfull if author will explain this strange syntax with @* $\endgroup$ – stiv Nov 3 '15 at 14:52
  • 1
    $\begingroup$ 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 $\endgroup$ – Jason B. Nov 3 '15 at 14:58
  • 2
    $\begingroup$ @JasonB Actually ? and @ acts weird together. Sometimes @ is any number of lowercase characters and sometimes not. $\endgroup$ – ybeltukov Nov 3 '15 at 16:34
5
$\begingroup$
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}]

$\endgroup$
  • $\begingroup$ How can I automatically get correct interval Interval[-0.25,10100] from Mathematica? $\endgroup$ – stiv Nov 3 '15 at 14:27
  • $\begingroup$ @stiv good point, I should answer the question :) $\endgroup$ – Kuba Nov 3 '15 at 14: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.