Only by doing the substitution by hand, I guess. You write your own
function to pull out the sqrt's:
>>> def presub(expr, reps):
... sr = [p for p in expr.atoms(Pow) if p.exp is S.Half]
... for s in sr:
... ssub = s.subs(reps)
... if not ssub.is_real:
... return S.NaN
... return expr.subs(reps)
...
>>> presub(x,{x:0})
0
>>> presub(sqrt(x-1)*sqrt(x-3),{x:0})
nan
In [20]: powsimp(E, force=True)
Out[20]:
_________________
╲╱ (x - 3)⋅(x - 1)
In [21]: powsimp(E, force=True).subs(x, 0)
Out[21]:
___
╲╱ 3
Making it return nan instead is more difficult. Something like
Chris's solution should work (depending on what kinds of expressions
you want it to work on). You could probably hack the core to make I
give nan, but that would (obviously) break a lot of stuff.
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>