Drake wrote:
> Has anybody considered using the python "with" statement? I know
> that's not what the keyword is used for, but wouldn't it be cool if
> you could write:
>
> with a > 0:
> simplify(...)
>
> On Nov 3, 4:10 pm, "Ondrej Certik" <[EMAIL PROTECTED]> wrote:
>
>> On Sun, Nov 2, 2008 at 7:46 PM, Vinzent Steinberg
>>
>>
>>
>> <[EMAIL PROTECTED]> wrote:
>>
>>
>>> On Nov 2, 3:30 am, Alan Bromborsky <[EMAIL PROTECTED]> wrote:
>>>
>>>> Suppose you have a calculation where you are simplifying
>>>> r*sin(theta)/sqrt(r**2*sin(theta)**2). Is there a way of specifying
>>>> that r > 0 and 0 < theta < pi so that the result will simplify to 1
>>>> rather than
>>>> r*sin(theta)/(|r||sin(theta)|).
>>>>
>>> Have you tried this?
>>>
>>>>>> r = Symbol('r', positive=True)
>>>>>> r.is_positive
>>>>>>
>>> True
>>>
>>> More complicated assumptions like 0 < theta < pi is afaik currently
>>> not possible, but hopefully it will be implemented soon:
>>>
>>> Seehttp://code.google.com/p/sympy/issues/detail?id=1047&q=assumptions.
>>>
>> Thanks for the reply. Indeed, any help with assumptions is very much
>> appreciated.
>>
>> Ondrej
>>
>
> >
>
>
Currently I am using the following code to remove the abs operation for
my simple cases -
sym_type = sympy.core.symbol.Symbol
pow_type = sympy.core.power.Pow
abs_type = sympy.abs
mul_type = sympy.core.mul.Mul
def unabs(x):
if type(x) == mul_type:
y = unabs(x.args[0])
for yi in x.args[1:]:
y *= unabs(yi)
return(y)
if type(x) == pow_type:
y = 1/unabs(x.args[0])
return(y)
if len(x.args) == 0:
return(x)
if type(x) == abs_type:
return(x.args[0])
return(x)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---