You need to include the assumptions in the call to refine:
>>> refine(sqrt((x - y)**2), Q.positive(x - y))
x - y
If I remember correctly, the `assuming` context manager also works for
this, but I can't be certain.
On Monday, November 10, 2014 6:30:25 PM UTC-6, Andrew Spielberg wrote:
>
> Hi Aaron,
>
> Thanks for the reply. One of the main things I'm hoping to do is make
> absolute values go away. I frequently in my code am getting things like (x
> - y) / Abs(x - y). I know x - y is > 0, so this is just 1.
>
> I should note that when I run your code, I get the following:
>
> In [1]: x, y = symbols('x y')
>
> In [2]: refine(sqrt((x - y)**2))
> Out[2]:
> __________
> ╱ 2
> ╲╱ (x - y)
>
> In [3]: Q.positive(x - y)
> Out[3]: Q.positive(x - y)
>
> In [4]: refine(sqrt((x - y)**2))
> Out[4]:
> __________
> ╱ 2
> ╲╱ (x - y)
>
>
> On Mon, Nov 10, 2014 at 7:13 PM, Aaron Meurer <[email protected]
> <javascript:>> wrote:
>
>> Q is just a namespace for the assumptions, like Q.positive or Q.real.
>>
>> refine() simplifies things based on assumptions. This example returns x -
>> y, because sqrt((x - y)**2) is equal to x - y if x - y is positive (but not
>> in general).
>>
>> What kinds of simplifications are you expecting to get out of your
>> constraints?
>>
>> Aaron Meurer
>>
>>
>> On Mon, Nov 10, 2014 at 5:42 PM, Andrew Spielberg <[email protected]
>> <javascript:>> wrote:
>>
>>> Hi Aaron,
>>>
>>> Thanks for the speedy reply. I'm not sure I fully understand what this
>>> example does, or how. Could you perhaps elaborate? What is Q? What is
>>> the difference between refine and simplify?
>>>
>>> I should note that the entirety of my constraints will be linear, so if
>>> the current functionality can do that, that's enough.
>>>
>>> -Andy S.
>>>
>>> On Mon, Nov 10, 2014 at 5:06 PM, Aaron Meurer <[email protected]
>>> <javascript:>> wrote:
>>>
>>>> There is a framework to do this with refine, like refine(sqrt((x -
>>>> y)**2), Q.positive(x - y)), but not much is implemented yet, so the
>>>> simplifications possible are quite limited (in fact, there's not much more
>>>> than the one that I just showed that is implemented).
>>>>
>>>> Aaron Meurer
>>>>
>>>> On Mon, Nov 10, 2014 at 3:58 PM, Andrew Spielberg <[email protected]
>>>> <javascript:>> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> When creating variables, I know you can provide certain constraints on
>>>>> the domain of that variable. For instance, one could say that a certain
>>>>> variable, x, is positive, real, rational, etc. These constraints affect
>>>>> the way the simplify function behaves.
>>>>>
>>>>> I am wondering, without creating auxiliary variables, can add other
>>>>> constraints? For example, if I have a variable x that always must be
>>>>> greater than another variable y, can I specify:
>>>>>
>>>>> x > y
>>>>>
>>>>> in some way, and have the simplifier intelligently know how to handle
>>>>> it? I know I could change my representation to be a = (x - y) and do
>>>>> everything in terms of my variable a, and set a positive, but this is
>>>>> less
>>>>> than ideal and will not work in a lot of my cases.
>>>>>
>>>>> If there is no way to set these assumptions, is there some other
>>>>> recommended way to do intelligent simplification in some way?
>>>>>
>>>>> -Andy S.
>>>>>
>>>>> --
>>>>> 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] <javascript:>.
>>>>> To post to this group, send email to [email protected]
>>>>> <javascript:>.
>>>>> Visit this group at http://groups.google.com/group/sympy.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/sympy/80f87d8d-1504-40f6-b6d4-efb08cdcc824%40googlegroups.com
>>>>>
>>>>> <https://groups.google.com/d/msgid/sympy/80f87d8d-1504-40f6-b6d4-efb08cdcc824%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> --
>>>> 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] <javascript:>.
>>>> To post to this group, send email to [email protected]
>>>> <javascript:>.
>>>> Visit this group at http://groups.google.com/group/sympy.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/sympy/CAKgW%3D6L3OorvtGQaXp7RUg2RGtVweSgUk2XNQ_tDs%2BqYB5-iMg%40mail.gmail.com
>>>>
>>>> <https://groups.google.com/d/msgid/sympy/CAKgW%3D6L3OorvtGQaXp7RUg2RGtVweSgUk2XNQ_tDs%2BqYB5-iMg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>>> 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] <javascript:>.
>>> To post to this group, send email to [email protected]
>>> <javascript:>.
>>> Visit this group at http://groups.google.com/group/sympy.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sympy/CAM6e1JdxBKnfSxEMPxJnUqkd7XwOdkU4fddaqPRQmqGAaMZO-A%40mail.gmail.com
>>>
>>> <https://groups.google.com/d/msgid/sympy/CAM6e1JdxBKnfSxEMPxJnUqkd7XwOdkU4fddaqPRQmqGAaMZO-A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] <javascript:>
>> .
>> Visit this group at http://groups.google.com/group/sympy.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2Bn0vvxOd3H%2B-4rRdQOh4Std7uCfjzFudvbs9gQzOM5yQ%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2Bn0vvxOd3H%2B-4rRdQOh4Std7uCfjzFudvbs9gQzOM5yQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/7e94d8e3-09f9-424b-9d63-4f5a0c4842ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.