Re: [sage-devel] Bug with NumberField
Thank you ! Le mardi 30 octobre 2018 15:33:29 UTC+1, vdelecroix a écrit : > > solved at > > https://trac.sagemath.org/ticket/26593 > > Le 26/10/2018 à 16:48, 'Paul Mercat' via sage-devel a écrit : > > Thank you. So the bug is with the test of equality in QQbar, not with > > NumberField. > > Do you know how to solve this problem with QQbar ? > > > > I tried to look at where is the error, and it looks like there is an > > infinite loop: > > > > > /Users/mercatp/sage-8.2/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_compiled.pyx > > in sage.rings.polynomial.polynomial_compiled.abc_pd.eval > (build/cythonized/sage/rings/polynomial/polynomial_compiled.c:6599)() > 506 507 cdef int eval(abc_pd self, object vars, object coeffs) > except -2:--> 508 pd_eval(self.left, vars, coeffs)509 > pd_eval(self.right, vars, coeffs)510 self.value = > self.left.value * self.right.value + coeffs[self.index] > > > /Users/mercatp/sage-8.2/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_compiled.pyx > > in sage.rings.polynomial.polynomial_compiled.pd_eval > (build/cythonized/sage/rings/polynomial/polynomial_compiled.c:3574)() > 352 cdef inline int pd_eval(generic_pd pd, object vars, object coeffs) > except -2:353 if pd.value is None:--> 354 pd.eval(vars, > coeffs)355 pd.hits += 1356 > > > > > > But I don't know how to avoid this loop, because I don't know what do > this > > code... > > > > Paul > > > > Le vendredi 26 octobre 2018 16:04:57 UTC+2, John Cremona a écrit : > >> > >> > >> > >> On Fri, 26 Oct 2018 at 13:07, 'Paul Mercat' via sage-devel < > >> sage-...@googlegroups.com > wrote: > >> > >>> Hi ! > >>> > >>> I have a strange bug with NumberField: when I do > >>> > >>> sage: pi = x^7 - 2*x^6 + x^3 - 2*x^2 + 2*x - 1 > >>> sage: b = pi.roots(ring=QQbar)[3][0] > >>> sage: pi = b.minpoly() > >>> sage: K = NumberField(pi, 'b', embedding=b) > >>> > >>> it works well. But if I execute it a second time, then it never > >>> terminates! > >>> Do you have a explanation and a correction to this problem ? > >>> > >> > >> How strange. The first 3 lines are fine the second time. So is the > >> number field construction when you leave out the embedding. > >> > >> When a number field is constructed it is cached so that a new > construction > >> returns the same object, and not a copy, where possible. In your case > that > >> means checking that the embeddings are the same, which means checking > that > >> two elements of QQbar are the same. That can be expensive. > >> > >> If you do > >> b1 = pi.roots(ring=QQbar)[3][0] > >> b2 = pi.roots(ring=QQbar)[3][0] > >> > >> and then > >> > >> b1==b2 > >> > >> it also takes ages. I cannot remember the algorithm here but it does > not > >> look optimal; it may be working effectively in a field of degree 7*6 > or > >> possibly 7!. I note that > >> > >> d=b1-b2 > >> d==0 > >> > >> yields True immediately. > >> > >> John > >> > >> > >>> > >>> Thank, > >>> Paul > >>> > >>> > >>> -- > >>> 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+...@googlegroups.com . > >>> To post to this group, send email to sage-...@googlegroups.com > >>> . > >>> Visit this group at https://groups.google.com/group/sage-devel. > >>> For more options, visit https://groups.google.com/d/optout. > >>> > >> > > > -- 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 https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Bug with NumberField
solved at https://trac.sagemath.org/ticket/26593 Le 26/10/2018 à 16:48, 'Paul Mercat' via sage-devel a écrit : Thank you. So the bug is with the test of equality in QQbar, not with NumberField. Do you know how to solve this problem with QQbar ? I tried to look at where is the error, and it looks like there is an infinite loop: /Users/mercatp/sage-8.2/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_compiled.pyx in sage.rings.polynomial.polynomial_compiled.abc_pd.eval (build/cythonized/sage/rings/polynomial/polynomial_compiled.c:6599)()506 507 cdef int eval(abc_pd self, object vars, object coeffs) except -2:--> 508 pd_eval(self.left, vars, coeffs)509 pd_eval(self.right, vars, coeffs)510 self.value = self.left.value * self.right.value + coeffs[self.index] /Users/mercatp/sage-8.2/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_compiled.pyx in sage.rings.polynomial.polynomial_compiled.pd_eval (build/cythonized/sage/rings/polynomial/polynomial_compiled.c:3574)()352 cdef inline int pd_eval(generic_pd pd, object vars, object coeffs) except -2:353 if pd.value is None:--> 354 pd.eval(vars, coeffs)355 pd.hits += 1356 But I don't know how to avoid this loop, because I don't know what do this code... Paul Le vendredi 26 octobre 2018 16:04:57 UTC+2, John Cremona a écrit : On Fri, 26 Oct 2018 at 13:07, 'Paul Mercat' via sage-devel < sage-...@googlegroups.com > wrote: Hi ! I have a strange bug with NumberField: when I do sage: pi = x^7 - 2*x^6 + x^3 - 2*x^2 + 2*x - 1 sage: b = pi.roots(ring=QQbar)[3][0] sage: pi = b.minpoly() sage: K = NumberField(pi, 'b', embedding=b) it works well. But if I execute it a second time, then it never terminates! Do you have a explanation and a correction to this problem ? How strange. The first 3 lines are fine the second time. So is the number field construction when you leave out the embedding. When a number field is constructed it is cached so that a new construction returns the same object, and not a copy, where possible. In your case that means checking that the embeddings are the same, which means checking that two elements of QQbar are the same. That can be expensive. If you do b1 = pi.roots(ring=QQbar)[3][0] b2 = pi.roots(ring=QQbar)[3][0] and then b1==b2 it also takes ages. I cannot remember the algorithm here but it does not look optimal; it may be working effectively in a field of degree 7*6 or possibly 7!. I note that d=b1-b2 d==0 yields True immediately. John Thank, Paul -- 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+...@googlegroups.com . To post to this group, send email to sage-...@googlegroups.com . Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout. -- 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 https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Bug with NumberField
Le 26/10/2018 à 16:04, John Cremona a écrit : On Fri, 26 Oct 2018 at 13:07, 'Paul Mercat' via sage-devel < sage-devel@googlegroups.com> wrote: Hi ! I have a strange bug with NumberField: when I do sage: pi = x^7 - 2*x^6 + x^3 - 2*x^2 + 2*x - 1 sage: b = pi.roots(ring=QQbar)[3][0] sage: pi = b.minpoly() sage: K = NumberField(pi, 'b', embedding=b) it works well. But if I execute it a second time, then it never terminates! Do you have a explanation and a correction to this problem ? How strange. The first 3 lines are fine the second time. So is the number field construction when you leave out the embedding. When a number field is constructed it is cached so that a new construction returns the same object, and not a copy, where possible. In your case that means checking that the embeddings are the same, which means checking that two elements of QQbar are the same. That can be expensive. If you do b1 = pi.roots(ring=QQbar)[3][0] b2 = pi.roots(ring=QQbar)[3][0] and then b1==b2 it also takes ages. I cannot remember the algorithm here but it does not look optimal; it may be working effectively in a field of degree 7*6 or possibly 7!. I note that d=b1-b2 d==0 yields True immediately. There is a shortcut for this kind of issues in qqbar.py implemented with the function (line 2158) def cmp_elements_with_same_minpoly(a, b, p) Apparently this is avoided in the present situation... Vincent -- 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 https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Bug with NumberField
Thank you. So the bug is with the test of equality in QQbar, not with NumberField. Do you know how to solve this problem with QQbar ? I tried to look at where is the error, and it looks like there is an infinite loop: /Users/mercatp/sage-8.2/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_compiled.pyx in sage.rings.polynomial.polynomial_compiled.abc_pd.eval (build/cythonized/sage/rings/polynomial/polynomial_compiled.c:6599)()506 507 cdef int eval(abc_pd self, object vars, object coeffs) except -2:--> 508 pd_eval(self.left, vars, coeffs)509 pd_eval(self.right, vars, coeffs)510 self.value = self.left.value * self.right.value + coeffs[self.index] /Users/mercatp/sage-8.2/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_compiled.pyx in sage.rings.polynomial.polynomial_compiled.pd_eval (build/cythonized/sage/rings/polynomial/polynomial_compiled.c:3574)()352 cdef inline int pd_eval(generic_pd pd, object vars, object coeffs) except -2: 353 if pd.value is None:--> 354 pd.eval(vars, coeffs)355 pd.hits += 1356 But I don't know how to avoid this loop, because I don't know what do this code... Paul Le vendredi 26 octobre 2018 16:04:57 UTC+2, John Cremona a écrit : > > > > On Fri, 26 Oct 2018 at 13:07, 'Paul Mercat' via sage-devel < > sage-...@googlegroups.com > wrote: > >> Hi ! >> >> I have a strange bug with NumberField: when I do >> >> sage: pi = x^7 - 2*x^6 + x^3 - 2*x^2 + 2*x - 1 >> sage: b = pi.roots(ring=QQbar)[3][0] >> sage: pi = b.minpoly() >> sage: K = NumberField(pi, 'b', embedding=b) >> >> it works well. But if I execute it a second time, then it never >> terminates! >> Do you have a explanation and a correction to this problem ? >> > > How strange. The first 3 lines are fine the second time. So is the > number field construction when you leave out the embedding. > > When a number field is constructed it is cached so that a new construction > returns the same object, and not a copy, where possible. In your case that > means checking that the embeddings are the same, which means checking that > two elements of QQbar are the same. That can be expensive. > > If you do > b1 = pi.roots(ring=QQbar)[3][0] > b2 = pi.roots(ring=QQbar)[3][0] > > and then > > b1==b2 > > it also takes ages. I cannot remember the algorithm here but it does not > look optimal; it may be working effectively in a field of degree 7*6 or > possibly 7!. I note that > > d=b1-b2 > d==0 > > yields True immediately. > > John > > >> >> Thank, >> Paul >> >> >> -- >> 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+...@googlegroups.com . >> To post to this group, send email to sage-...@googlegroups.com >> . >> Visit this group at https://groups.google.com/group/sage-devel. >> For more options, visit https://groups.google.com/d/optout. >> > -- 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 https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Bug with NumberField
On Fri, 26 Oct 2018 at 13:07, 'Paul Mercat' via sage-devel < sage-devel@googlegroups.com> wrote: > Hi ! > > I have a strange bug with NumberField: when I do > > sage: pi = x^7 - 2*x^6 + x^3 - 2*x^2 + 2*x - 1 > sage: b = pi.roots(ring=QQbar)[3][0] > sage: pi = b.minpoly() > sage: K = NumberField(pi, 'b', embedding=b) > > it works well. But if I execute it a second time, then it never terminates! > Do you have a explanation and a correction to this problem ? > How strange. The first 3 lines are fine the second time. So is the number field construction when you leave out the embedding. When a number field is constructed it is cached so that a new construction returns the same object, and not a copy, where possible. In your case that means checking that the embeddings are the same, which means checking that two elements of QQbar are the same. That can be expensive. If you do b1 = pi.roots(ring=QQbar)[3][0] b2 = pi.roots(ring=QQbar)[3][0] and then b1==b2 it also takes ages. I cannot remember the algorithm here but it does not look optimal; it may be working effectively in a field of degree 7*6 or possibly 7!. I note that d=b1-b2 d==0 yields True immediately. John > > Thank, > Paul > > > -- > 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 https://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. > -- 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 https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Bug with NumberField
Hi ! I have a strange bug with NumberField: when I do sage: pi = x^7 - 2*x^6 + x^3 - 2*x^2 + 2*x - 1 sage: b = pi.roots(ring=QQbar)[3][0] sage: pi = b.minpoly() sage: K = NumberField(pi, 'b', embedding=b) it works well. But if I execute it a second time, then it never terminates! Do you have a explanation and a correction to this problem ? Thank, Paul -- 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 https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
[sage-devel] Bug in NumberField? and use of coercions in equality tests
Hi! Here are two independent Sage 4.1 sessions which demonstrate that the construction of NumberField's is context dependent: sage: K.x = CyclotomicField(5)[] sage: W.a = NumberField(x^2 + 1) sage: W Number Field in a with defining polynomial x^2 + 1 over its base field sage: W1 = NumberField(x^2+1,'a') sage: K.x = CyclotomicField(5)[] sage: W.a = NumberField(x^2 + 1) sage: W Number Field in a with defining polynomial x^2 + 1 In fact: sage: W1 is W0 True Related example, in a fresh Sage session: sage: p = x^2 + 1 sage: K.x = CyclotomicField(5)[] sage: q = x^2 + 1 sage: bool(p==q) True Personal analysis: p and q do not have the same ground field, but are considered as equal, because p can be coerced into q. This confuses the caching mechanism of NumberField. Can anyone familiar with NumberField confirm? Very personal interpretation: this is a strong argument for limiting as much as possible the use of coercions in equality testing. Cheers, Nicolas PS: This behavior appears with Sage 4.1, with or without the Sage-Combinat patches applied. For some reason the tests for number_field_rel trigger it in the first case, but not the second one. William: what should I do about this? I don't want to wait for a fix to release sagecombinat 4.1. Should I just ignore this? comment out the tests? -- Nicolas M. Thiéry Isil nthi...@users.sf.net http://Nicolas.Thiery.name/ --~--~-~--~~~---~--~~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~--~~~~--~~--~--~---