On Mon, Jun 8, 2009 at 8:45 AM, smichr<[email protected]> wrote:
>
>
>
> On Jun 8, 5:50 am, Ondrej Certik <[email protected]> wrote:
>>
>> I agree that some deep backtrace is confusing, especially if it's
>> something that the users do frequently.
>>
>> Could you please paste here the exact output, so that we can discuss
>> some particular example?
>>
> ###
>>>> from sympy import *
>>>> x=var('x')
>>>> roots(1/x,x).keys()
> Traceback (most recent call last):
>  File "<interactive input>", line 1, in <module>
>  File "C:\Documents and Settings\chris\sympy\sympy\polys
> \rootfinding.py", line 190, in roots
>    f = Poly(f, *symbols)
>  File "C:\Documents and Settings\chris\sympy\sympy\polys
> \polynomial.py", line 402, in __new__
>    terms = Poly._decompose(poly, *symbols)
>  File "C:\Documents and Settings\chris\sympy\sympy\polys
> \polynomial.py", line 545, in _decompose
>    raise PolynomialError("Can't decompose %s" % factor)
> PolynomialError: Can't decompose 1/x
> ###
>
> OK, that's not to obtuse. You know what the routine was trying to do
> and you learn that poly can only change things thare are x**m-like in
> appearance.
>
> But, knowing that roots like to have a poly, if you try to send it a
> poly then...
>
> ###
>>>> roots((1/x).as_poly(x))
> Traceback (most recent call last):
>  File "<interactive input>", line 1, in <module>
>  File "C:\Documents and Settings\chris\sympy\sympy\polys
> \rootfinding.py", line 190, in roots
>    f = Poly(f, *symbols)
>  File "C:\Documents and Settings\chris\sympy\sympy\polys
> \polynomial.py", line 300, in __new__
>    raise SymbolsError("No symbols were given")
> SymbolsError: No symbols were given
> ###
>
> The poly that you sent (which here is obviously not x**m-like, but
> could have been an expression generated along the way in some
> computation) *was not a poly* (it was None because the poly step
> failed) and it complains that no symbols were given when clearly a
> symbol was given.
>
> So I don't know...perhaps that lesson would have been not to try to do
> too much of the work (i.e. making it into a poly first). Or perhaps
> rootfinding should have complained that no function was received
> rather than passing off the None and "no symbol" to poynomial and
> getting a complaint from there that "there was no symbol".

I think the behaviour above could be improved by adding couple checks
if you can convert to Poly and if not, do something else meaningful,
or raise a meaningful exception.

As long as you are rising the exception at the right point, it's fine.
The only thing that I am against is a code like this:

try:
   something
except:
   do something else

which is extremely error prone, since it catches all exceptions raised
by "something", thus hiding bugs.

Ondrej

Ondrej

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