Symbols with known interval ranges

1,336 views
Skip to first unread message

Nathan Alison

unread,
Feb 18, 2012, 1:37:23 AM2/18/12
to sy...@googlegroups.com, mroc...@gmail.com
It would be nice if we could have variables take an interval as an input argument, to replace or augment the current system of "is_something" flags.

Say, 

>>> x = Symbol('x', domain=Interval(0, oo))
>>> x.is_positive
True
>>> x.is_real
True
>>> x.is_bounded
False

The variable x would carry around its interval, and we could use interval arithmetic on functions of variables to find the interval of an expression:

>>> x = Symbol('x', domain=Interval(-1, 1))
>>> y = Symbol('y', domain=Interval(0, 2))
>>> (x+y).domain
Interval(-1, 3)

Currently (I think), there's no way to specify a range that a symbol can take to this extent. Hopefully, notation like this would simplify things like solving equations within a bounded domain, perhaps.

If we want to be really ambitious, since an Interval is simply a type of set, we can extend this notation to support arbitrary sets, though specifying a symbol to be in the set of Reals would not add any extra functionality...

krastano...@gmail.com

unread,
Feb 18, 2012, 10:51:57 AM2/18/12
to sy...@googlegroups.com, mroc...@gmail.com
It seems to me that the assumption system is a better place to put all
this. I may be wrong but I was left with the impression that it is
meant to replace all the is_something stuff.

> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/peRtdNF7OioJ.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

Matthew Rocklin

unread,
Feb 18, 2012, 1:03:35 PM2/18/12
to sy...@googlegroups.com
Interval arithmetic seems to be more powerful than either of the current assumptions systems in the case of real variables. I've heard people mention this topic on the listhost before. Is there any past attempt/knowledge on this subject?

Aaron Meurer

unread,
Feb 18, 2012, 4:51:15 PM2/18/12
to sy...@googlegroups.com
My hopes are that the new assumptions will be able to handle interval
arithmetic, or actually any kind of set arithmetic. Trying to get the
old assumptions to do it would be unfruitful and a waste of time,
since the design doesn't really allow for it at all.

My vision is that we should be able to replace things like
ask(Q.positive(x)) with any boolean, like ask(x > 0). For sets, we
will need some kind of In() or Contains() object, so we can say
ask(In(x, Interval(0, 1))). And the same for assume(). We can then
have standard sets like QQ (rationals), ZZ (integers), etc., which we
could use anywhere in set arithmetic. We should also allow to build
sets using set builder notation.

As far as I know, no one's really gotten anywhere with it beyond
what's already implemented. It would make a great GSoC project,
though.

Aaron Meurer

Nathan Alison

unread,
Feb 19, 2012, 3:20:42 AM2/19/12
to sy...@googlegroups.com, mroc...@gmail.com
The current problem I'm working on it creating a better density function for transformations of single random variables in sympy.stats. I'd like to be able to do transform a random variable X and change its interval

expr = X**2 # Or exp(X) or (X + mu)/sigma or anything...
I = pspace(expr).domain.set # Usually [0, oo) or (-oo, oo) or [a,b]
z = Symbol('z', domain=lambdify(expr, X)(I))

Can anyone tell me how to do this with the current assumptions system?

Aaron Meurer

unread,
Feb 19, 2012, 4:05:49 AM2/19/12
to sy...@googlegroups.com, mroc...@gmail.com
The current assumptions system doesn't support interval domains
(unless the interval happens to be (-oo, oo), [0, oo), (0, oo), (oo,
0), or (oo, 0]). How exactly would you like the z Symbol to act?
That is, where do you plan to use the doman assumption?

Aaron Meurer

> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/sympy/-/XhTQP8nXwiMJ.

Nathan Alison

unread,
Feb 19, 2012, 11:46:09 PM2/19/12
to sy...@googlegroups.com
To solve an equation with f(x) = z for x.
Reply all
Reply to author
Forward
0 new messages