I'm renaming TransformationSet to ImageSet (I think this is a more precise name).
https://github.com/sympy/sympy/pull/2341 2340 is in by the way but the interface will change shortly to >>> Interval(0, 1).image(x, 2*x) [0, 2] On Tue, Jul 30, 2013 at 8:33 AM, Matthew Rocklin <[email protected]> wrote: > Really I just like working on sets. They're fairly simple and fun to play > with. Here is a pull request adding a `transform` method to sets > > https://github.com/sympy/sympy/pull/2340 > > > On Tue, Jul 30, 2013 at 7:14 AM, Ben Lucato <[email protected]> wrote: > >> Awesome! You are a gentleman and a scholar, Matthew Rocklin. >> >> Thanks for letting me know there is no way to do this in the current >> sympy. >> >> >> On 30 July 2013 13:18, Matthew Rocklin <[email protected]> wrote: >> >>> At some point we might do a simplify sort of treatment for sets. >>> >>> In the meantime something like the following could work in the case of >>> monotonic functions. In general we know how to transform Intervals and >>> FiniteSets. We know that unions and intersections will compose well with >>> these transformations. That's all you really need. >>> >>> This should eventually be broken out into methods on the various classes: >>> >>> def transform_set(x, expr, set): >>> """ Transform a set by an expression >>> >>> >>> domain = Interval(-pi, 0, True, True) + Interval(0, pi/2, True, >>> True) >>> (0, pi/2) U (-pi, 0) >>> >>> >>> transform(x, 2*x, domain) >>> (0, pi) U (-2*pi, 0) >>> >>> >>> transform(x, x**2, domain) >>> (0, pi**2) >>> """ >>> if isinstance(set, Union): >>> return Union(transform_set(x, expr, arg) for arg in set.args) >>> if isinstance(set, Intersection): >>> return Intersection(transform_set(x, expr, arg) for arg in >>> set.args) >>> z = Dummy('z', real=True) >>> f = Lambda(x, expr) >>> if isinstance(set, Interval): >>> # TODO: manage left_open and right_open better >>> left, right = f(set.left), f(set.right) >>> return Interval(Min(left, right), Max(left, right), >>> set.left_open, set.right_open) >>> if isinstance(set, FiniteSet): >>> return FiniteSet(map(f, set)) >>> >>> >>> >>> On Mon, Jul 29, 2013 at 9:37 PM, Ben Lucato <[email protected]>wrote: >>> >>>> Thanks - I updated to the git master and now the TransformationSet >>>> works. Is there some way to take this new TransformationSet object and >>>> rewrite it as a Union/Interval? >>>> >>>> i.e. >>>> >>>> get this: >>>> >>>> Interval(-2*pi, 0, True, True) + Interval(0, pi, True, True) >>>> >>>> >>>> On Tuesday, 30 July 2013 10:34:48 UTC+10, Matthew wrote: >>>> >>>>> This is what I get. Can you verify that things don't work for you? >>>>> This was done in sympy/master. >>>>> >>>>> In [1]: domain = Interval(-pi, 0, True, True) + Interval(0, pi/2, >>>>> True, True) >>>>> >>>>> In [2]: new_domain = TransformationSet(Lambda(x, 2*x), domain) >>>>> >>>>> In [3]: domain >>>>> Out[3]: >>>>> ⎛ π⎞ >>>>> ⎜0, ─⎟ ∪ (-π, 0) >>>>> ⎝ 2⎠ >>>>> >>>>> In [4]: new_domain >>>>> Out[4]: >>>>> ⎧ ⎛ π⎞ ⎫ >>>>> ⎨2⋅x | x ∊ ⎜0, ─⎟ ∪ (-π, 0)⎬ >>>>> ⎩ ⎝ 2⎠ ⎭ >>>>> >>>>> In [5]: 3*pi/4 in new_domain >>>>> Out[5]: True >>>>> >>>>> >>>>> >>>>> On Mon, Jul 29, 2013 at 7:24 PM, Ben Lucato <[email protected]>wrote: >>>>> >>>>>> Howdy, say I do: >>>>>> >>>>>> domain = Interval(-pi, 0, True, True) + Interval(0, pi/2, True, True) >>>>>> >>>>>> >>>>>> I could hope to do a transformation to dilate this domain by a factor >>>>>> 2 from the origin, like so: >>>>>> >>>>>> >>>>>> new_domain = domain.replace(lambda expr: expr.is_Real, lambda expr: >>>>>> 2*expr) >>>>>> OR: >>>>>> new_domain = TransformationSet(Lambda(x, 2*x), domain) >>>>>> >>>>>> in either case, checking: >>>>>> >>>>>> 3*pi/4 in new_domain >>>>>> >>>>>> returns False. >>>>>> >>>>>> I may be using TransformationSet incorrectly - I just looked in the >>>>>> docs and it looked like something relevant. Perhaps it only works for >>>>>> sets? >>>>>> >>>>>> -- >>>>>> 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 [email protected]. >>>>>> >>>>>> Visit this group at >>>>>> http://groups.google.com/**group/sympy<http://groups.google.com/group/sympy> >>>>>> . >>>>>> For more options, visit >>>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>>>> . >>>>>> >>>>>> >>>>>> >>>>> >>>>> -- >>>> 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 [email protected]. >>>> To post to this group, send email to [email protected]. >>>> Visit this group at http://groups.google.com/group/sympy. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>> >>> -- >>> 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/WlG3XirFAzM/unsubscribe. >>> To unsubscribe from this group and all its topics, send an email to >>> [email protected]. >>> >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/sympy. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> >> >> -- >> >> >> Ben Lucato >> >> ---------------------------------------------------------------------------------- >> Phone: +61 400 159 632 | Email: [email protected] >> >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/sympy. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.
