Algebrite
Algebrite copied to clipboard
some way to get real roots from n^(1/3)
It'd be nice if there were a way to get (-1)^(1/3) to return -1 instead of a complex number. I can get it using roots(x^3+1), but it doesn't seem like there's any easy way for me to pick the real root out of the roots list.
some thoughts:
- I would probably not change the "power" routines, which (seem to) use the "value with the least value of the argument" definition of "principal root". That's also the default result in Mathematica.
- given the above, I'd take one of the two routes: a) we add a "real roots" flag to the roots function or b) we add a way to filter out the complex numbers from the result (either a dedicated function or some more generic filter function since I added support for anonymous functions)
a) would probably result in much faster root calculations as some roots are unwieldy to say the least, and we can probably leave many calculations out.
(At any rate, given that "iscomplexnumber" and "isimaginarynumber" are defined, I'd hope that an Algebrite script should be able to scan the results to only get the real results... is that not the case? Or you prefer not to use an Algebrite script anyways?)
One option is to give the same guarantee as in Mathematica
The ordering used by Root i.e. [f,k] takes real roots to come before complex ones, and takes complex conjugate pairs of roots to be adjacent
I haven't written algebrite scripts before. I can't figure out how to use iscomplexnumber, but this seems to work:
droots(e)=do(
theroots=roots(e),
realroot=theroots[1],
for(
test(and(imag(realroot)!=0,
imag(theroots[i])=0),
realroot=theroots[i]
), i,1,shape(theroots)[1]
),
realroot)
droots(x^3+107)