> any idea how to get the number of > terms in a better way in Sage?): > > sage: K.<sqrt3> = QuadraticField(3) > sage: L.<sqrt5> = K.extension(x^2-5) > sage: R.<a1,a2,a3,a4,a5> = L[] > sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^18 > CPU times: user 2.43 s, sys: 3.94 ms, total: 2.44 s > Wall time: 2.44 s > sage: len(str(f).split("+")) > 7315 > > > You may do "len(list(f))". To avoid the creation of the list: "sum(1 for _ in f)".
Some timings: sage: %time len(str(f).split("+")) CPU times: user 8.2 s, sys: 3.14 s, total: 11.3 s Wall time: 12 s 7315 sage: %time len(list(f)) CPU times: user 699 ms, sys: 98.1 ms, total: 797 ms Wall time: 770 ms 7315 sage: %time len(f.monomials()) CPU times: user 127 ms, sys: 13.7 ms, total: 141 ms Wall time: 135 ms 7315 sage: %time sum(1 for _ in f) CPU times: user 69.6 ms, sys: 18.8 ms, total: 88.3 ms Wall time: 85.2 ms 7315 Sébastien -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.