On Sun, Mar 4, 2012 at 2:39 AM, Aaron Meurer <[email protected]> wrote: > On Sun, Mar 4, 2012 at 2:35 AM, Chris Smith <[email protected]> wrote: >> >> >> On Sun, Mar 4, 2012 at 10:39 AM, prateek papriwal >> <[email protected]> wrote: >>> >>> so somehow we need to merge nsimplify() method into sqrt() method . >>> >>> in that case when we call sqrt(4.41) >>> >>> automatically sqrt(nsimplify(4.41,rational=True)) will be called . >>> >>> >> >> Since 4.41 is a Float, we don't assume that it is an exact number so the >> conversion happens (as Aaron is noted) upon instantiation of the sqrt and >> 2.1 is returned. If you know the 4.41 is exact you can enter it as a string >> to Rational: >> >> >>> sqrt(Rational('4.41')) >> 21/10 >> >> Also, it seems the following could be added to Pow: >> >> def _eval_is_rational(self): >> p = self.func(*self.as_base_exp()) # in case it's unevaluated >> if not p.is_Pow: >> return p.is_rational >> b, e = p.as_base_exp() >> if e.is_Rational and not e.is_Integer and b.is_Rational: >> return False >> >> This would allow False to be returned for sqrt(3).is_rational (or True for >> is_irrational). > > +1 to that. > > Aaron Meurer
You can make it a little more general by noting that rational**integer is always rational (even if they are symbolic). Aaron Meurer -- 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.
