On Mon, Dec 19, 2011 at 1:34 AM, Vincent MAILLE <[email protected]> wrote:
> Hello,
>
> I want to eval an expression in R, e.g for E=sqrt(x-1)*sqrt(x-3),
> E.sub(x,0).is_real is true :(
> Is there a way ton force calculus in R sqrt(-1)=nan for exemple ?
>

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

-- 
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