Le 08/11/2016 à 08:43, Vincent Delecroix a écrit : > Concerning representation of algebraic numbers, it is printed as an > exact rational if and only if it is stored as an exact rational. It > will be if the method exactify has been called on the underlying > representation of the number. Here is a simple example that shows the > difference >
Ha, yes... But I am not sure to understand. sage: y=QQbar(cos(pi/18)) sage: y.radical_expression() 1/4*(4*(1/128*I*sqrt(3) + 1/128)^(1/3) + 1)/(1/128*I*sqrt(3) + 1/128)^(1/6) ok! good! sage: y 0.9848077530122081? + 0.?e-18*I ok. sage: y.imag() 0.?e-18 sage: y.imag() == 0 True I accept this as 0 is "in" 0.?e-18 Now: sage: y.exactify() sage: y 0.9848077530122081? + 0.?e-18*I raaahhh ! grrr ! t. > sage: a = QQbar(2).sqrt() + QQbar(3).sqrt() > sage: b = a**2 - 2*QQbar(6).sqrt() > > sage: b > 5.000000000000000? > sage: type(b._descr) # b is an formal sum > <class 'sage.rings.qqbar.ANBinaryExpr'> > > sage: b == 5 # calls exactify > True > sage: b # now prints as 5... > 5 > sage: type(b._descr) # because it *is* an exact rational > <class 'sage.rings.qqbar.ANRational'> > > > Vincent > > On 7 November 2016 at 17:28, Nils Bruin <nbr...@sfu.ca> wrote: >> On Monday, November 7, 2016 at 5:59:14 AM UTC-8, tdumont wrote: >>> >>> >>> okay. Now let us construct a polynomial from l: >>> sage: print sum([l[i]*z^i for i in range(0,len(l))]) >>> (-0.4022786138875136? + 0.?e-18*I)*z + 1 >>> ^^^^^ >>> Why? an imaginary part? >>> ---------------------- >> >> There are polynomials for which this doesn't happen. It would be better to >> include enough information to reproduce your observations. >> >> The representation you see is a float approximation to the algebraic number. >> You can approximate real numbers quite well with complex numbers with >> non-zero imaginary part. >> >> sage: P.<x>=QQbar[] >> sage: u=[u for u in (x^3+x+1).roots(multiplicities=false) if u.imag()==0][0] >> sage: u >> -0.6823278038280193? >> sage: v=(u*QQbar.zeta(8))^4; v >> -0.2167565719512513? + 0.?e-18*I >> sage: v.imag() == 0 >> True >> sage: v._exact_value() >> a^4 where a^12 + 2*a^8 + 5*a^4 + 1 = 0 and a in 0.4824786170789168? - >> 0.4824786170789168?*I >> sage: v.simplify() >> sage: v >> -0.2167565719512513? >> sage: v._exact_value() >> a^2 - a where a^3 + a - 1 = 0 and a in 0.6823278038280193? >> sage: v.minpoly() >> x^3 + 2*x^2 + 5*x + 1 >> sage: v.minpoly().roots(QQbar) >> [(-0.2167565719512513?, 1), >> (-0.891621714024375? - 1.954093392512700?*I, 1), >> (-0.891621714024375? + 1.954093392512700?*I, 1)] >> >> (I have seen cases where "simplify" didn't do the trick, but recomputing the >> algebraic number by taking the roots of the minimal polynomial did) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sage-support" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sage-support+unsubscr...@googlegroups.com. >> To post to this group, send email to sage-support@googlegroups.com. >> Visit this group at https://groups.google.com/group/sage-support. >> For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
<<attachment: tdumont.vcf>>