[sage-devel] Re: Comparison and logarithm on .py vs. interactive
Please see https://trac.sagemath.org/ticket/18970 -- 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] Re: Comparison and logarithm on .py vs. interactive
Ralf Stephan wrote: > On Saturday, August 27, 2016 at 7:05:28 AM UTC+2, Jori Mäntysalo wrote: > > But shouldn't it work in any case? I.e. comparison of > log(a+b*c^2...) to > some number should work when a,b,c... are sage Integers. > > > log(integer) will not be expanded numerically except for log(0) and log(1). > If you want it expanded, either give a float argument, eg log(2.), or > append n(). N() wasn't the problem, but (also) rounding: (s is 12 here.) sage: n*log(n, 2) 24 sage: n*log(n, 2r) 8*log(8)/log(2) sage: N(n*log(n, 2r)) 24.0 sage: 2*s < n*log(n, 2) False sage: 2*s > n*log(n, 2) False sage: 2*s > n*log(n, 2r) 24 > 8*log(8)/log(2) sage: bool(2*s > n*log(n, 2r)) True sage: bool(2r*s > n*log(n, 2r)) True sage: bool(2r*s > n*log(n, 2)) False sage: 24 > N(n*log(n, 2r)) True -leif -- 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] Re: Comparison and logarithm on .py vs. interactive
On Saturday, August 27, 2016 at 7:05:28 AM UTC+2, Jori Mäntysalo wrote: > > But shouldn't it work in any case? I.e. comparison of log(a+b*c^2...) to > some number should work when a,b,c... are sage Integers. > log(integer) will not be expanded numerically except for log(0) and log(1). If you want it expanded, either give a float argument, eg log(2.), or append n(). -- 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] Re: Comparison and logarithm on .py vs. interactive
On Fri, 26 Aug 2016, leif wrote: For me, it /does/ make a difference (using Python vs. Sage literals): sage: if 2*s > n*log(n, 2): print "True" sage: if 2r*s > n*log(n, 2r): print "True" True OK, I don't know what I did wrong in my test. Now I got the same result. Thanks! * * * But shouldn't it work in any case? I.e. comparison of log(a+b*c^2...) to some number should work when a,b,c... are sage Integers. -- Jori Mäntysalo
[sage-devel] Re: Comparison and logarithm on .py vs. interactive
leif wrote: > Jori Mäntysalo wrote: >> On Fri, 26 Aug 2016, leif wrote: >> >>> Hmmm, does Posets.BooleanLattice() care whether you pass an int or an >>> Integer? (I.e., does the return type of its methods change?) >> >> No: >> >> sage: P = Posets.BooleanLattice(3) >> sage: Q = Posets.BooleanLattice(3r) >> sage: P == Q >> True >> sage: P is Q >> True > > I rather meant e.g. type(P.cardinality()), but since 'P is Q' holds, > they won't differ. > > No idea... For me, it /does/ make a difference (using Python vs. Sage literals): $ ./sage ┌┐ │ SageMath version 7.3, Release Date: 2016-08-04 │ │ Type "notebook()" for the browser-based notebook interface.│ │ Type "help()" for help.│ └┘ sage: from sage.combinat.posets.poset_examples import Posets sage: from sage.misc.functional import log sage: P = Posets.BooleanLattice(3); n = P.cardinality(); s = P._hasse_diagram.size() sage: if 2*s > n*log(n, 2): print "True" sage: from sage.combinat.posets.poset_examples import Posets sage: from sage.misc.functional import log sage: P = Posets.BooleanLattice(3r); n = P.cardinality(); s = P._hasse_diagram.size() sage: if 2r*s > n*log(n, 2r): print "True" True sage: And it's caused by this: sage: type(n*log(n, 2)) sage: type(n*log(n, 2r)) (FWIW, while .cardinality() returns Integer, ._hasse_diagram.size() returns int, but that doesn't matter here.) -leif -- 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] Re: Comparison and logarithm on .py vs. interactive
Jori Mäntysalo wrote: > On Fri, 26 Aug 2016, leif wrote: > >> Hmmm, does Posets.BooleanLattice() care whether you pass an int or an >> Integer? (I.e., does the return type of its methods change?) > > No: > > sage: P = Posets.BooleanLattice(3) > sage: Q = Posets.BooleanLattice(3r) > sage: P == Q > True > sage: P is Q > True I rather meant e.g. type(P.cardinality()), but since 'P is Q' holds, they won't differ. No idea... -leif -- 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] Re: Comparison and logarithm on .py vs. interactive
On Fri, 26 Aug 2016, leif wrote: Hmmm, does Posets.BooleanLattice() care whether you pass an int or an Integer? (I.e., does the return type of its methods change?) No: sage: P = Posets.BooleanLattice(3) sage: Q = Posets.BooleanLattice(3r) sage: P == Q True sage: P is Q True -- Jori Mäntysalo
[sage-devel] Re: Comparison and logarithm on .py vs. interactive
Jori Mäntysalo wrote: > On Fri, 26 Aug 2016, leif wrote: > >> Apparently log() behaves differently depending on whether it is called >> with Sage Integers or Python ints. (Not sure whether the other integer >> literal also matters here.) >> >> (You should get the same in the Sage session when using 2r instead of 2, >> or Integer(2) instead of 2 in the Python file.) > > Tested with 2r on Sage session, makes no difference. Hmmm, does Posets.BooleanLattice() care whether you pass an int or an Integer? (I.e., does the return type of its methods change?) -leif -- 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] Re: Comparison and logarithm on .py vs. interactive
On Fri, 26 Aug 2016, leif wrote: Apparently log() behaves differently depending on whether it is called with Sage Integers or Python ints. (Not sure whether the other integer literal also matters here.) (You should get the same in the Sage session when using 2r instead of 2, or Integer(2) instead of 2 in the Python file.) Tested with 2r on Sage session, makes no difference. -- Jori Mäntysalo
[sage-devel] Re: Comparison and logarithm on .py vs. interactive
Jori Mäntysalo wrote: > sage: def foo(): > .: from sage.combinat.posets.poset_examples import Posets > .: from sage.misc.functional import log > .: P = Posets.BooleanLattice(3); n = P.cardinality(); s = > P._hasse_diagram.size() > .: if 2*s > n*log(n, 2): print "True" > .: > sage: foo() > sage: > > So, in this case the comparison is False. Now when I add exactly same > function on end of lattices.py and compile I got > > sage: sage.combinat.posets.lattices.foo() > True > sage: > > What's wrong? Somehow comparison and logaritms don't mix (again). Apparently log() behaves differently depending on whether it is called with Sage Integers or Python ints. (Not sure whether the other integer literal also matters here.) (You should get the same in the Sage session when using 2r instead of 2, or Integer(2) instead of 2 in the Python file.) -leif > > * * * > > Is there a function to get 2-based logarithm of integer in Sage? In > Python 3.3 there is, but we use Python 2.x. > -- 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.