Sorry for the double post.  It seems replace is very weak as well, not
being able to detect multiples :-/

In [60]: expr.replace(math.Abs(guardlength - 0.5*length), guardlength -
0.5*length)
Out[60]: width*(-2*guardlength + length + Abs(2*guardlength -
length))/Abs(2*guardlength - length)

In [61]: expr.replace(math.Abs(2*guardlength - length), 2*guardlength -
length)
Out[61]: 0


On Fri, Jan 2, 2015 at 11:47 PM, Andrew Spielberg <aespielb...@gmail.com>
wrote:

> This may be a dumb question, but can you please explain what is going on
> here...?  exp was made using simpify, expr was created from scratch.
> Replace operates on them differently.
>
> In [48]: exp
> Out[48]: width*(-2*guardlength + length + Abs(2*guardlength -
> length))/Abs(2*guardlength - length)
>
> In [49]: expr
> Out[49]: width*(-2*guardlength + length + Abs(2*guardlength -
> length))/Abs(2*guardlength - length)
>
> In [50]: exp.replace(math.Abs(2*guardlength - length), 2*guardlength -
> length)
> Out[50]: width*(-2*guardlength + length + Abs(2*guardlength -
> length))/Abs(2*guardlength - length)
>
> In [51]: expr.replace(math.Abs(2*guardlength - length), 2*guardlength -
> length)
> Out[51]: 0
>
> In [52]: exp == expr
> Out[52]: False
>
> -Andy S.
>
> On Fri, Jan 2, 2015 at 10:06 PM, Aaron Meurer <asmeu...@gmail.com> wrote:
>
>>
>>
>> On Fri, Jan 2, 2015 at 12:13 PM, Andrew Spielberg <aespielb...@gmail.com>
>> wrote:
>>
>>> Hi guys,
>>>
>>> Thanks for your help so far.  I am revisiting this after ignoring this
>>> issue for a while.
>>>
>>> I'm still trying to come up with a good way to use this.  I've noticed
>>> the following:
>>>
>>> Say:
>>> a = Symbol('a')
>>> b = Symbol('b')
>>> assumptions = Q.positive(a - b)
>>> expr = 1/Abs(a - b)
>>>
>>> If I try:
>>>
>>> refine(expr, assumptions)
>>>
>>> it returns:
>>>
>>> 1/(a - b)
>>>
>>> as desired.  But, if I try:
>>>
>>> expr = Abs(b - a)/Abs(a - b)
>>>
>>> it returns:
>>>
>>> │-b + a│
>>> ────────
>>>  a - b
>>>
>>> I can add an assumption that:
>>>
>>> assumptions = assumptions &  Q.negative(b - a)
>>>
>>> And then refining returns 1.  But then I can do something like:
>>>
>>> expr = Abs(0.5*b - 0.5*a)/Abs(a - b)
>>>
>>> And it fails again.  Is the pattern matcher this weak?  Is there any way
>>> to get what I want that doesn't require refine, or is there a better way to
>>> use refine to get what I want?  My assumptions are simple - they will all
>>> be linear equations of variables.
>>>
>>
>> I don't think refine is even using a pattern matcher. It really isn't
>> very powerful yet, as I noted earlier in this thread.
>>
>> replace() has a better pattern matching abilities if that's all you're
>> going for.
>>
>> Aaron Meurer
>>
>>
>>> -Andy S.
>>>
>>> On Fri, Nov 14, 2014 at 6:03 PM, Aaron Meurer <asmeu...@gmail.com>
>>> wrote:
>>>
>>>> Note that if you want to kill all abs in your expression, there's an
>>>> easier way. expr.replace(Abs, Id)
>>>>
>>>> Aaron Meurer
>>>>
>>>> On Fri, Nov 14, 2014 at 5:02 PM, Aaron Meurer <asmeu...@gmail.com>
>>>> wrote:
>>>>
>>>>> As I said, it's *very* proof of concept. Many advanced things don't
>>>>> work.
>>>>>
>>>>> In this case, I think the issue is with the assumptions in general.
>>>>> They can't deduce from the facts And(Q.positive(-beamwidth),
>>>>> Q.positive(-length), Q.positive(0.9*beamwidth - length))
>>>>>  that 0.866025403784438*beamwidth - length is positive.  I'm not even
>>>>> sure what algorithms need to be implemented to make this work.
>>>>>
>>>>> Why are your beamwidth and length variables negative? From the
>>>>> variable names, they sound like they should be positive?
>>>>>
>>>>> Aaron Meurer
>>>>>
>>>>> On Wed, Nov 12, 2014 at 9:44 PM, Andrew Spielberg <
>>>>> aespielb...@gmail.com> wrote:
>>>>>
>>>>>> refine_abs isn't doing the trick here either.  Am I using this module
>>>>>> incorrectly?
>>>>>>
>>>>>> On Tue, Nov 11, 2014 at 6:09 PM, Andrew Spielberg <
>>>>>> aespielb...@gmail.com> wrote:
>>>>>>
>>>>>>> Thanks guys.  This seems to be mostly working so far.
>>>>>>>
>>>>>>> Any idea why this wouldn't be, though?
>>>>>>>
>>>>>>> In [1]: assumptions
>>>>>>> Out[1]: And(Q.positive(-beamwidth), Q.positive(-length),
>>>>>>> Q.positive(0.9*beamwidth - length))
>>>>>>>
>>>>>>> In [2]: exp
>>>>>>> Out[2]: 0.866025403784439*beamwidth*(0.866025403784438*beamwidth -
>>>>>>> length)/Abs(0.866025403784438*beamwidth - length)
>>>>>>>
>>>>>>> In [3]: math.refine(exp, assumptions)
>>>>>>> Out[3]: 0.866025403784439*beamwidth*(0.866025403784438*beamwidth -
>>>>>>> length)/Abs(0.866025403784438*beamwidth - length)
>>>>>>>
>>>>>>> (math is my sympy module)
>>>>>>>
>>>>>>> A little confused here as to why the fraction wouldn't simplify out.
>>>>>>>  (0.866025403784438*beamwidth - length)/Abs(0.866025403784438*beamwidth 
>>>>>>> -
>>>>>>> length) should be 1.
>>>>>>>
>>>>>>> -Andy S.
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Nov 11, 2014 at 3:16 AM, Mateusz Paprocki <matt...@gmail.com
>>>>>>> > wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> On 11 November 2014 01:13, Aaron Meurer <asmeu...@gmail.com> wrote:
>>>>>>>> > Q is just a namespace for the assumptions, like Q.positive or
>>>>>>>> Q.real.
>>>>>>>> >
>>>>>>>> > refine() simplifies things based on assumptions.
>>>>>>>>
>>>>>>>> I think we shouldn't use "refine()" and "simplifies" together as
>>>>>>>> this
>>>>>>>> only can increase confusion. Simplification implies that there is an
>>>>>>>> optimisation procedure applied. refine() just transforms an
>>>>>>>> expression
>>>>>>>> given some facts about it.
>>>>>>>>
>>>>>>>> Mateusz
>>>>>>>>
>>>>>>>>  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 <
>>>>>>>> aespielb...@gmail.com>
>>>>>>>> > 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 <
>>>>>>>> asmeu...@gmail.com> 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 <
>>>>>>>> aespielb...@gmail.com>
>>>>>>>> >>> 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 sympy+unsubscr...@googlegroups.com.
>>>>>>>> >>>> To post to this group, send email to sympy@googlegroups.com.
>>>>>>>> >>>> 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
>>>>>>>> .
>>>>>>>> >>>> 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 sympy+unsubscr...@googlegroups.com.
>>>>>>>> >>> To post to this group, send email to sympy@googlegroups.com.
>>>>>>>> >>> 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
>>>>>>>> .
>>>>>>>> >>>
>>>>>>>> >>> 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 sympy+unsubscr...@googlegroups.com.
>>>>>>>> >> To post to this group, send email to sympy@googlegroups.com.
>>>>>>>> >> 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
>>>>>>>> .
>>>>>>>> >>
>>>>>>>> >> 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 sympy+unsubscr...@googlegroups.com.
>>>>>>>> > To post to this group, send email to sympy@googlegroups.com.
>>>>>>>> > 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
>>>>>>>> .
>>>>>>>> >
>>>>>>>> > 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 sympy+unsubscr...@googlegroups.com.
>>>>>>>> To post to this group, send email to sympy@googlegroups.com.
>>>>>>>> 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/CAGBZUCY_dQUZ095a2Gw8bXZZ3y%3D4co2vMvijApVCivw5yNNiAw%40mail.gmail.com
>>>>>>>> .
>>>>>>>> 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 sympy+unsubscr...@googlegroups.com.
>>>>>> To post to this group, send email to sympy@googlegroups.com.
>>>>>> 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/CAM6e1JfXy2vdW5Hgq_ZFwjAsML29K1UerEqt_xjsevDcBhRRjQ%40mail.gmail.com
>>>>>> <https://groups.google.com/d/msgid/sympy/CAM6e1JfXy2vdW5Hgq_ZFwjAsML29K1UerEqt_xjsevDcBhRRjQ%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 sympy+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to sympy@googlegroups.com.
>>>> 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%3D6KUCB7Lg3x2TnXXRj__0O2FtYZ9K3BxLp6esoWJhRHpmA%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/sympy/CAKgW%3D6KUCB7Lg3x2TnXXRj__0O2FtYZ9K3BxLp6esoWJhRHpmA%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 sympy+unsubscr...@googlegroups.com.
>>> To post to this group, send email to sympy@googlegroups.com.
>>> 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/CAM6e1JdWEo0qOJwXWcimfOJw-dm3MN7S%2Bsen90Ac6hSf1%2Bo6YQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/sympy/CAM6e1JdWEo0qOJwXWcimfOJw-dm3MN7S%2Bsen90Ac6hSf1%2Bo6YQ%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 sympy+unsubscr...@googlegroups.com.
>> To post to this group, send email to sympy@googlegroups.com.
>> 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%3D6J7o%2BTeZ-XmbYt_PUbSK57hD629pQn2vSAupObHr6P%3DEw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/sympy/CAKgW%3D6J7o%2BTeZ-XmbYt_PUbSK57hD629pQn2vSAupObHr6P%3DEw%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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/CAM6e1JdGbsiLXxPbq00X9oH8Pqn1fBV_PRttL5BugrcXxbzXig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to