expr.is_Pow # if you're sure the thing will be a Basic i.e. this will fail
if expr is 1 and not S.One
or
expr.__class__ is Pow  # otherwise


On Fri, Aug 12, 2011 at 10:21 AM, Alan Bromborsky <[email protected]>wrote:

> On 08/12/2011 02:44 AM, Aaron Meurer wrote:
>
>> Unfortunately, relational assumptions have not yet been implemented,
>> though they have been planned for a long time (see
>> http://code.google.com/p/**sympy/issues/detail?id=1047<http://code.google.com/p/sympy/issues/detail?id=1047>).
>>  I don't know
>> how dynamic of assumptions you want to be able to put on theta.  If
>> you just want to be able to assume that cos is positive, you might be
>> able to substitute it with a positive symbol and then back substitute
>> once the square root is reduced.
>>
>> Aaron Meurer
>>
>> On Thu, Aug 11, 2011 at 5:25 PM, Alan Bromborsky<[email protected]**>
>>  wrote:
>>
>>> On 08/11/2011 07:04 PM, Tomo Lazovich wrote:
>>>
>>> I just tried this in isympy and as long as you specify both real and
>>> positive, it seems to work:
>>>
>>> In [1]: r = Symbol('r', real=True, positive=True)
>>>
>>> In [2]: sqrt(r*r)
>>> Out[2]: r
>>>
>>> In [3]: r = Symbol('r', real=True)
>>>
>>> In [4]: sqrt(r*r)
>>> Out[4]: │r│
>>>
>>>
>>> On Thu, Aug 11, 2011 at 6:01 PM, Alan Bromborsky<[email protected]**>
>>> wrote:
>>>
>>>> I have a symbol r which should be assumed real and greater than zero.
>>>>  What I want is for sqrt(r*r) to evaluate to r.  Can this be currently
>>>> done
>>>> in sympy.  I am trying to clean up some old code that has a lot of hacks
>>>> in
>>>> it (curvilinear coordinates).
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups
>>>> "sympy" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> sympy+unsubscribe@**googlegroups.com<sympy%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/**group/sympy?hl=en<http://groups.google.com/group/sympy?hl=en>
>>>> .
>>>>
>>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "sympy" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> sympy+unsubscribe@**googlegroups.com<sympy%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/**group/sympy?hl=en<http://groups.google.com/group/sympy?hl=en>
>>> .
>>>
>>> That worked fine.  Now for another similar and more difficult problem.
>>> Evaluate sqrt(r**2*cos(theta)**2)  where -pi/2<theta<pi/2.  This should
>>> evaluate to r*cos(theta).   Are symbol assumptions flexible enough yet to
>>> handle this case (again curvilinear coordinates)?
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "sympy" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> sympy+unsubscribe@**googlegroups.com<sympy%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/**group/sympy?hl=en<http://groups.google.com/group/sympy?hl=en>
>>> .
>>>
>>>  My solution is as follows -
>
>        def reduce_sqr(expr):
>            args = expr.args
>            if len(args) == 0:
>                return(sqrt(expr))
>            else:
>                if str(type(expr)) == "<class 'sympy.core.power.Pow'>":
>                    args = expr.args
>                    if args[1] == 2:
>                        e_mag = args[0]
>                    else:
>                        e_mag = sqrt(expr)
>                else:
>                    e_mag = 1
>                    for arg in args:
>                        if str(type(arg)) == "<class
> 'sympy.core.power.Pow'>":
>                            x = arg.args
>                            if len(x) == 2 and x[1] == 2:
>                                e_mag *= x[0]
>                        else:
>                            return(sqrt(expr))
>            return(e_mag)
>
> For the special case of reducing squares (normalizing basis vectors) for
> curvilinear coordinates it should be OK.  One question I have is when I do
> something like -
>
>    str(type(expr)) == "<class 'sympy.core.power.Pow'>"
>
> I would like to say -
>
>    type(expr) == xxx
>
> but I don't know what xxx should be.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to sympy+unsubscribe@**
> googlegroups.com <sympy%[email protected]>.
> For more options, visit this group at http://groups.google.com/**
> group/sympy?hl=en <http://groups.google.com/group/sympy?hl=en>.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to