Question about assumptions and sorting symbolic values

22 views
Skip to first unread message

BR

unread,
Oct 15, 2013, 5:47:25 PM10/15/13
to sy...@googlegroups.com
Hey,

I've been trying to find some information online on SymPy's assumptions module and unfortunately I can't find an answer to my question. Is it possible to declare symbols with assumptions in such a way that they are respected when sorting them? For instance, is it possible to declare a symbol x with the assumption that 0<x<1, so that sorting [w, w**2, w**3] gives [w**3, w**2, w]?

Thanks.

Aaron Meurer

unread,
Oct 15, 2013, 7:45:38 PM10/15/13
to sy...@googlegroups.com
I think the logic you want isn't implemented. Right now, the
assumptions module doesn't really do anything with interval type
assumptions, like 0 < x < 1. It only knows about assumptions like
positive or negative.

Of course, if all you want to do is sort symbols by their exponent,
that is not too difficult to do, especially if you know for sure that
each element of your list is a power of that symbol. You just need to
define an appropriate key function and use it when sorting.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

BR

unread,
Oct 15, 2013, 8:08:09 PM10/15/13
to sy...@googlegroups.com
Unfortunately, the example is just a basic case of the functionality I'd want to use - I need a reliable way of sorting symbolic values like that. Other software I've tried struggles with this a lot, so I thought SymPy would work better - unfortunately not! Thank you for your reply anyway.

Aaron Meurer

unread,
Oct 15, 2013, 8:12:14 PM10/15/13
to sy...@googlegroups.com
If you know the ordering is total (i.e., for any two expressions one is greater than the other in your given domain), you could just evaluate at some value in (0, 1) and sort by that. 

By the way, how general are your expressions? Do they have symbolic constants (more than one symbol)? Are they always polynomials or rational functions?

Aaron Meurer

Bartosz Regula

unread,
Oct 15, 2013, 8:22:51 PM10/15/13
to sy...@googlegroups.com
I need to write a very general function that will work whatever values and assumptions you plug into it - the (0,1) example is just a simple case that I wanted to check to make sure it's actually possible to do. Thank you for your help, I will keep looking for different solutions!


--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/v_J3MYJsJTs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages