[sage-support] Re: from lists to sets
On Sep 25, 2008, at 7:53 PM, cesarnda wrote: > I am using the "set([])" function, and is a set of vectors, I want to > convert it to a set because I want to use the methods for sets > > On Sep 25, 9:09 pm, Jason Grout <[EMAIL PROTECTED]> wrote: >> cesarnda wrote: >>> is there a function that can convert a list to a set without >>> verifying >>> if there are equal elements?, i.e., I am creating a large set >>> (cardinality = 9^5) of vectors, so the constructions takes too long >>> ( around 25 seconds), but I know all the vectors are distinct, so is >>> there a way to add an element into a set without verifying if the >>> element is already in the set? or >> >> What sort of sets are you using? The python sets use a >> dictionary, so >> it is generally very fast to see if an element already exists in >> the set. >> >> If you know everything is distinct, why don't you just keep it as >> a list? >> >> Jason I doubt there is a way to make a set without uniqueness verification, but if it's taking so long, perhaps make sure the hash and equality functions aren't slow. I believe sets are based on hashtables, so even for that range things should be fast enough. sage: L = srange(9^5) sage: time S = set(L) CPU times: user 0.01 s, sys: 0.01 s, total: 0.01 s How long does [hash(a) for a in your_list] take? - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: How to do: is_Integer(sqrt(a^2+b^2))
On Sep 25, 2008, at 6:11 PM, William Stein wrote: > > On Thu, Sep 25, 2008 at 6:06 PM, Robert Bradshaw > <[EMAIL PROTECTED]> wrote: >> >> >> On Sep 25, 2008, at 5:43 PM, William Stein wrote: >> >>> >>> On Thu, Sep 25, 2008 at 5:33 PM, Quicksilver_Johny >>> <[EMAIL PROTECTED]> wrote: If c=sqrt(a^2+b^2) How would I check if c is an integer in order to get a true/false value. I tried is_Integer(ZZ(c)), this returns true when c is an integer, but ZZ(c) returns an error when c is not an integer. >>> >>> Try using Python's try/except: >>> >>> try: >>> ZZ(c) >>> # c is an integer >>> except TypeError: >>> # c isn't an integer >> >> These is_* sure are causing a lot of confusion lately... > > Indeed! I like Mike Hansen's (or your) proposal to get > rid of them all from the global namespace, and replace > them only by "is_lowercase_method_name" functions > that are all conceptually meaningful. Of course leave > the type-checking is_Uppercase's around, but don't > put them in all.py's. > > What do you guys think? +1 for sure. >> Rational numbers also have an is_integral method, so you could >> also dos >> >> c=sqrt(a^2+b^2) > > If a,b are integers, then c is either an integer or an element > of the symbolic ring... Oops... I guess one could also do "if c in ZZ" for a one-liner. - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: How to do: is_Integer(sqrt(a^2+b^2))
On Sep 26, 12:06 am, Robert Bradshaw <[EMAIL PROTECTED]> wrote: > > Indeed! I like Mike Hansen's (or your) proposal to get > > rid of them all from the global namespace, and replace > > them only by "is_lowercase_method_name" functions > > that are all conceptually meaningful. Of course leave > > the type-checking is_Uppercase's around, but don't > > put them in all.py's. > > > What do you guys think? > > +1 for sure. The patch is up at #4192 and will be merge shortly unless there is some last minute breakage. > - Robert Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: lists in cython
On Sep 25, 6:45 pm, cesarnda <[EMAIL PROTECTED]> wrote: ... > result = [] ... > result.append(n) ... > if I compile in the notebook I get a html file showing me the > following lines in yellow: > > def primes(int kmax): > result = [] > result.append(n) > return result > > how can I modify this example to avoid the yellow lines? As other people pointed out, there is not much hope for the "def" and the "return" line. But wouldn't it be possible to do cdef list result = [] ? And isn't there a quick, dirty and potentially unsafe way of appending to a list? Or at least for assigning a value to some list entry? I think I have seen it somewhere, but I don't remember the name. Cheers Simon --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Two Dimensional Plots
On Sep 25, 2008, at 5:15 PM, Erik Lane wrote: > Yes, I saw that in the solution of the other one (and have changed my > plots to take this into account), but what is the advantage of the > aspect ratio default *not* being 1? I'm very curious. I'm not a > mathematician, just a student going through college, so I would love > to hear the why behind this. > > Also, does this have much of an effect on all my other plots? Do I > have to pay attention every time to see if the axes are at different > ratios to each other? (Although in many plots I guess they easily > could be anyways.) The "interesting" range for x and y are rarely a 1:1 aspect ratio (e.g. plot sin, exp, or even most polynomials on (-10,10)). However, for geometric objects like circles, I think the default aspect ratio should be 1:1. - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: lists in cython
On Sep 26, 2008, at 12:09 AM, Simon King wrote: > > On Sep 25, 6:45 pm, cesarnda <[EMAIL PROTECTED]> wrote: > ... >> result = [] > ... >> result.append(n) > > ... >> if I compile in the notebook I get a html file showing me the >> following lines in yellow: >> >> def primes(int kmax): >> result = [] >> result.append(n) >> return result >> >> how can I modify this example to avoid the yellow lines? > > As other people pointed out, there is not much hope for the "def" and > the "return" line. > > But wouldn't it be possible to do > cdef list result = [] Yep, you could do this. The resulting C code calls PyList_New(0) which is the fastest way to make a list. > And isn't there a quick, dirty and potentially unsafe way of appending > to a list? Since it knows result is a list (due to the cdef above), it uses PyList_Append, the fastest way to append to a list. > Or at least for assigning a value to some list entry? I > think I have seen it somewhere, but I don't remember the name. Yep. Currently it calls __Pyx_SetItemInt which does an inline runtime boundscheck and check for a list, and if it's OK uses a macro to reset the specified entry right there. We could (should) optimize this in the case it already knows it's a list, but with good branch prediction it's probably within 5% of as fast as it could be period. - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: bug in _fast_float_ with plot in sage 3.2.1?
Thanks, Mike! I remember that there was talk about including fast_float automatically in plot, so it's good to know it has happened already. Stan > Yes, it should work -- I'll fix this. However, you shouldn't have to > manually use fast float now. When you do plot([bv1,bv2],0,1), the > fast_float stuff will now (in 3.1.2) automatically get called in the > background. > > --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: question about DiGraph
Pong, All of this is documented, and you can get to it by typing sage: G.show? Normally, the Python/Sage way of dealing with objects is to put the object first, with a dot afterwards. Then, you can hit tab to see all the functions available for that object, and type one ? for docs, and ?? for source code. Emily Kirkman has written several versions of multi-edge plotting for graphs, but they have all gone to /dev/null due to problems with her laptop. Currently no code exists, and she has changed gears to work on databases. On Sep 25, 10:29 am, pong <[EMAIL PROTECTED]> wrote: > Thanks!! > > A more general question, how can I find out all the possible options > for a command, like "show" for example? > > I've tried show.option? which doesn't seem to work. > > On Sep 25, 9:56 am, "Mike Hansen" <[EMAIL PROTECTED]> wrote: > > > Hello, > > > On Thu, Sep 25, 2008 at 9:50 AM, pong <[EMAIL PROTECTED]> wrote: > > > > I'm still having problem in displaying the label of the edges using > > > DiGraph. I have read more from this group and tried: > > > > G=DiGraph({1:{1:['hola','hi'], 2:['two','dos']},2:{1:['one']}}, > > > loops=True, multiedges=True) > > > G.edges() > > > [(1, 1, 'hi'), (1, 1, 'hola'), (1, 2, 'dos'), (1, 2, 'two'), (2, 1, > > > 'one')] > > > > G.show() > > > > I expect to see two loops from 1 to 1 labeled by 'hola' and 'hi', > > > etc... > > > but the result of G.show() only show one loop and no lables on the > > > edges. > > > > Can someone tell me what am I missing? > > > You need to explicitly ask for edge labels to appear on the plot: > > > G.show(edge_labels=True) > > > The plotting code for graphs definitely needs some work, but luckily > > there is someone working on it. It looks like there is only one edge > > and one loop since they are drawn directly over each other. The same > > thing is going on with the labels. I hope we can get this fixed in > > the next release or two. > > > --Mike > > > > Thanks in advance > > > > On Sep 23, 9:15 pm, pong <[EMAIL PROTECTED]> wrote: > > >> I tried one of the examples (example 3 inDiGraph?) > > > >> g =DiGraph({0:{1:'x',2:'z',3:'a'}, 2:{5:'out'}}, > > >> implementation='networkx'); show(g) > > > >> However, I don't see any label of the edges, why? > > > >> Also, I think theDiGraphfunction is very useful for drawing finite > > >> automata (thanks!) My question is: does it support loop to a node? > > >> (which is essential in drawing automata) --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: How to do: is_Integer(sqrt(a^2+b^2))
> >> These is_* sure are causing a lot of confusion lately... > > > > Indeed! I like Mike Hansen's (or your) proposal to get > > rid of them all from the global namespace, and replace > > them only by "is_lowercase_method_name" functions > > that are all conceptually meaningful. Of course leave > > the type-checking is_Uppercase's around, but don't > > put them in all.py's. > > > > What do you guys think? > > +1 for sure. +1 -- name: Martin Albrecht _pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99 _www: http://www.informatik.uni-bremen.de/~malb _jab: [EMAIL PROTECTED] --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: lists in cython
On Sep 25, 2008, at 3:45 PM, cesarnda wrote: > > in http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ there is > the following example: > > def primes(int kmax): > cdef int n, k, i > cdef int p[1000] > result = [] > if kmax > 1000: > kmax = 1000 > k = 0 > n = 2 > while k < kmax: > i = 0 > while i < k and n % p[i] <> 0: > i = i + 1 > if i == k: > p[k] = n > k = k + 1 > result.append(n) > n = n + 1 > return result > > if I compile in the notebook I get a html file showing me the > following lines in yellow: > > def primes(int kmax): > result = [] > result.append(n) > return result > > how can I modify this example to avoid the yellow lines? You can't, but they're not "very" yellow (i.e. there's not really a faster way of doing those operations). - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Two Dimensional Plots
Robert Bradshaw wrote: > On Sep 25, 2008, at 5:15 PM, Erik Lane wrote: > >> Yes, I saw that in the solution of the other one (and have changed my >> plots to take this into account), but what is the advantage of the >> aspect ratio default *not* being 1? I'm very curious. I'm not a >> mathematician, just a student going through college, so I would love >> to hear the why behind this. >> >> Also, does this have much of an effect on all my other plots? Do I >> have to pay attention every time to see if the axes are at different >> ratios to each other? (Although in many plots I guess they easily >> could be anyways.) > > The "interesting" range for x and y are rarely a 1:1 aspect ratio > (e.g. plot sin, exp, or even most polynomials on (-10,10)). However, > for geometric objects like circles, I think the default aspect ratio > should be 1:1. > You've said this before too. For reference, this is http://trac.sagemath.org/sage_trac/ticket/2100 Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: lists in cython
I already did that and I get this: cdef list codeSet = [] __pyx_1 = PyList_New(0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_codeSet = __pyx_1; __pyx_1 = 0; and if I don't do it that way I get: addVector = [] __pyx_2 = PyList_New(0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} Py_DECREF(__pyx_v_addVector); __pyx_v_addVector = ((PyObject *)__pyx_2); __pyx_2 = 0; On Sep 26, 2:55 am, Robert Bradshaw <[EMAIL PROTECTED]> wrote: > On Sep 26, 2008, at 12:09 AM, Simon King wrote: > > > > > > > On Sep 25, 6:45 pm, cesarnda <[EMAIL PROTECTED]> wrote: > > ... > >> result = [] > > ... > >> result.append(n) > > > ... > >> if I compile in the notebook I get a html file showing me the > >> following lines in yellow: > > >> def primes(int kmax): > >> result = [] > >> result.append(n) > >> return result > > >> how can I modify this example to avoid the yellow lines? > > > As other people pointed out, there is not much hope for the "def" and > > the "return" line. > > > But wouldn't it be possible to do > > cdef list result = [] > > Yep, you could do this. The resulting C code calls PyList_New(0) > which is the fastest way to make a list. > > > And isn't there a quick, dirty and potentially unsafe way of appending > > to a list? > > Since it knows result is a list (due to the cdef above), it uses > PyList_Append, the fastest way to append to a list. > > > Or at least for assigning a value to some list entry? I > > think I have seen it somewhere, but I don't remember the name. > > Yep. Currently it calls __Pyx_SetItemInt which does an inline runtime > boundscheck and check for a list, and if it's OK uses a macro to > reset the specified entry right there. We could (should) optimize > this in the case it already knows it's a list, but with good branch > prediction it's probably within 5% of as fast as it could be period. > > - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Bug in plot?
Hi all, A student of mine noticed the following and it looks like a bug to me (at least with the documentation). >From the notebook with 3.1.2 (sage prompts added for readability): sage: plot? File: /home/jason/sage/local/lib/python2.5/site-packages/sage/plot/plot.py Type: Definition: plot(funcs, *args, **kwds) Docstring: Use plot by writing plot(X, ...) where X is a SAGE object (or list of SAGE objects) that either is callable and returns numbers that can be coerced to floats, or has a plot method that returns a GraphicPrimitive object. Type plot.options for a dictionary of the default options for plots. You can change this to change the defaults for all future plots. Use plot.reset() to reset to the default options. sage: plot.options Traceback (most recent call last): File "", line 1, in File "/home/jason/.sage/sage_notebook/worksheets/admin/32/code/44.py", line 6, in plot.options File "/home/jason/sage/local/lib/python2.5/site-packages/zope.interface-3.3.0-py2.5-linux-i686.egg/", line 1, in AttributeError: 'function' object has no attribute 'options' sage: plot.reset() Traceback (most recent call last): File "", line 1, in File "/home/jason/.sage/sage_notebook/worksheets/admin/32/code/46.py", line 6, in plot.reset() File "/home/jason/sage/local/lib/python2.5/site-packages/zope.interface-3.3.0-py2.5-linux-i686.egg/", line 1, in AttributeError: 'function' object has no attribute 'reset' Cheers, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Two Dimensional Plots
On Fri, Sep 26, 2008 at 7:36 AM, Jason Grout <[EMAIL PROTECTED]> wrote: > > Robert Bradshaw wrote: >> On Sep 25, 2008, at 5:15 PM, Erik Lane wrote: >> >>> Yes, I saw that in the solution of the other one (and have changed my >>> plots to take this into account), but what is the advantage of the >>> aspect ratio default *not* being 1? I'm very curious. I'm not a >>> mathematician, just a student going through college, so I would love >>> to hear the why behind this. >>> >>> Also, does this have much of an effect on all my other plots? Do I >>> have to pay attention every time to see if the axes are at different >>> ratios to each other? (Although in many plots I guess they easily >>> could be anyways.) >> >> The "interesting" range for x and y are rarely a 1:1 aspect ratio >> (e.g. plot sin, exp, or even most polynomials on (-10,10)). However, >> for geometric objects like circles, I think the default aspect ratio >> should be 1:1. >> > > > You've said this before too. For reference, this is > http://trac.sagemath.org/sage_trac/ticket/2100 > > > For further reference, I implemented 3d plotting that way, so the default when you make a sphere is a 1:1:1 aspect ratio. So I also agree. William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: lists in cython
On Sep 26, 2008, at 8:21 AM, cesarnda wrote: > > I already did that and I get this: > > cdef list codeSet = [] > > __pyx_1 = PyList_New(0); if (unlikely(!__pyx_1)) {__pyx_filename = > __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto > __pyx_L1_error;} > __pyx_v_codeSet = __pyx_1; > __pyx_1 = 0; > > > and if I don't do it that way I get: > > addVector = [] > > __pyx_2 = PyList_New(0); if (unlikely(!__pyx_2)) > {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = > __LINE__; goto __pyx_L1_error;} > Py_DECREF(__pyx_v_addVector); > __pyx_v_addVector = ((PyObject *)__pyx_2); > __pyx_2 = 0; Yes, that is correct. Is this not what you want? > > > On Sep 26, 2:55 am, Robert Bradshaw <[EMAIL PROTECTED]> > wrote: >> On Sep 26, 2008, at 12:09 AM, Simon King wrote: >> >> >> >> >> >>> On Sep 25, 6:45 pm, cesarnda <[EMAIL PROTECTED]> wrote: >>> ... result = [] >>> ... result.append(n) >> >>> ... if I compile in the notebook I get a html file showing me the following lines in yellow: >> def primes(int kmax): result = [] result.append(n) return result >> how can I modify this example to avoid the yellow lines? >> >>> As other people pointed out, there is not much hope for the "def" >>> and >>> the "return" line. >> >>> But wouldn't it be possible to do >>> cdef list result = [] >> >> Yep, you could do this. The resulting C code calls PyList_New(0) >> which is the fastest way to make a list. >> >>> And isn't there a quick, dirty and potentially unsafe way of >>> appending >>> to a list? >> >> Since it knows result is a list (due to the cdef above), it uses >> PyList_Append, the fastest way to append to a list. >> >>> Or at least for assigning a value to some list entry? I >>> think I have seen it somewhere, but I don't remember the name. >> >> Yep. Currently it calls __Pyx_SetItemInt which does an inline runtime >> boundscheck and check for a list, and if it's OK uses a macro to >> reset the specified entry right there. We could (should) optimize >> this in the case it already knows it's a list, but with good branch >> prediction it's probably within 5% of as fast as it could be period. >> >> - Robert > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Bug in plot?
Hi Jason, On Fri, Sep 26, 2008 at 9:05 AM, Jason Bandlow <[EMAIL PROTECTED]> wrote: > A student of mine noticed the following and it looks like a bug to me > (at least with the documentation). > This was a regression caused by the reworking of plot.py in 3.1.2. I've added a patch at http://trac.sagemath.org/sage_trac/ticket/4201 which fixes so things so that the old behavior works. --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: lists in cython
Actually I wanted it less yellow, if I do that or only codeSet = [] or codeSet = ([]) the result is the same. On Sep 26, 1:43 pm, Robert Bradshaw <[EMAIL PROTECTED]> wrote: > On Sep 26, 2008, at 8:21 AM, cesarnda wrote: > > > > > > > I already did that and I get this: > > > cdef list codeSet = [] > > > __pyx_1 = PyList_New(0); if (unlikely(!__pyx_1)) {__pyx_filename = > > __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto > > __pyx_L1_error;} > > __pyx_v_codeSet = __pyx_1; > > __pyx_1 = 0; > > > and if I don't do it that way I get: > > > addVector = [] > > > __pyx_2 = PyList_New(0); if (unlikely(!__pyx_2)) > > {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = > > __LINE__; goto __pyx_L1_error;} > > Py_DECREF(__pyx_v_addVector); > > __pyx_v_addVector = ((PyObject *)__pyx_2); > > __pyx_2 = 0; > > Yes, that is correct. Is this not what you want? > > > > > On Sep 26, 2:55 am, Robert Bradshaw <[EMAIL PROTECTED]> > > wrote: > >> On Sep 26, 2008, at 12:09 AM, Simon King wrote: > > >>> On Sep 25, 6:45 pm, cesarnda <[EMAIL PROTECTED]> wrote: > >>> ... > result = [] > >>> ... > result.append(n) > > >>> ... > if I compile in the notebook I get a html file showing me the > following lines in yellow: > > def primes(int kmax): > result = [] > result.append(n) > return result > > how can I modify this example to avoid the yellow lines? > > >>> As other people pointed out, there is not much hope for the "def" > >>> and > >>> the "return" line. > > >>> But wouldn't it be possible to do > >>> cdef list result = [] > > >> Yep, you could do this. The resulting C code calls PyList_New(0) > >> which is the fastest way to make a list. > > >>> And isn't there a quick, dirty and potentially unsafe way of > >>> appending > >>> to a list? > > >> Since it knows result is a list (due to the cdef above), it uses > >> PyList_Append, the fastest way to append to a list. > > >>> Or at least for assigning a value to some list entry? I > >>> think I have seen it somewhere, but I don't remember the name. > > >> Yep. Currently it calls __Pyx_SetItemInt which does an inline runtime > >> boundscheck and check for a list, and if it's OK uses a macro to > >> reset the specified entry right there. We could (should) optimize > >> this in the case it already knows it's a list, but with good branch > >> prediction it's probably within 5% of as fast as it could be period. > > >> - Robert --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Using sage to find point on a line a given distance from circle in 3D
Newbie to sage - trying to find a point on a line in 3D that is a specified distance from a circle (the line is not coplanar with the circle). Here's what I've inputed into sage: var("line_dir_x line_dir_y line_dir_z line_p_x line_p_y line_p_z cent_x cent_y cent_z norm_x norm_y norm_z u radius length") line_dir = vector([line_dir_x, line_dir_y, line_dir_z]) # direction of line line_p = vector([line_p_x, line_p_y, line_p_z]) # point on the line cent = vector([cent_x, cent_y, cent_z]) # center of circle norm = vector([norm_x, norm_y, norm_z])# normal to plane of circle p = line_p + u * line_dir diff0 = p - cent dist = diff0.dot_product(norm) diff1 = diff0 - dist * norm sqr_len = diff1.dot_product(diff1) closest_point1 = cent + (radius/sqrt(sqr_len))*diff1 diff2 = p - closest_point1 eq = length**Integer(2) == diff2.dot_product(diff2) solve([eq], u) Here's what eq looks like: rleg_len^2 == (-radius*(-norm_z*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_z*u + line_p_z - cent_z)/sqrt((-norm_z*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_z*u + line_p_z - cent_z)^2 + (- norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)^2 + (- norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)^2) + line_dir_z*u + line_p_z - cent_z)^2 + (-radius*(- norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)/sqrt((- norm_z*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_z*u + line_p_z - cent_z)^2 + (- norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)^2 + (- norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)^2) + line_dir_y*u + line_p_y - cent_y)^2 + (-radius*(- norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)/sqrt((- norm_z*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_z*u + line_p_z - cent_z)^2 + (- norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)^2 + (- norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)^2) + line_dir_x*u + line_p_x - cent_x)^2 I try to do the solve but it doesn't seem to terminate after several hours. Just looking for any pointers about finding an analytical solution to this seemingly simple problem. --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: lists in cython
On Sep 26, 2008, at 6:04 PM, cesarnda wrote: > Actually I wanted it less yellow, if I do that or only > > codeSet = [] > > or > > codeSet = ([]) > > the result is the same. You can't create a list in a "less yellow" way than calling PyList_New (0), and that's all its doing so you're optimal. - Robert > On Sep 26, 1:43 pm, Robert Bradshaw <[EMAIL PROTECTED]> > wrote: >> On Sep 26, 2008, at 8:21 AM, cesarnda wrote: >> >> >> >> >> >>> I already did that and I get this: >> >>> cdef list codeSet = [] >> >>> __pyx_1 = PyList_New(0); if (unlikely(!__pyx_1)) {__pyx_filename = >>> __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto >>> __pyx_L1_error;} >>> __pyx_v_codeSet = __pyx_1; >>> __pyx_1 = 0; >> >>> and if I don't do it that way I get: >> >>> addVector = [] >> >>> __pyx_2 = PyList_New(0); if (unlikely(!__pyx_2)) >>> {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = >>> __LINE__; goto __pyx_L1_error;} >>> Py_DECREF(__pyx_v_addVector); >>> __pyx_v_addVector = ((PyObject *)__pyx_2); >>> __pyx_2 = 0; >> >> Yes, that is correct. Is this not what you want? >> >> >> >>> On Sep 26, 2:55 am, Robert Bradshaw <[EMAIL PROTECTED]> >>> wrote: On Sep 26, 2008, at 12:09 AM, Simon King wrote: >> > On Sep 25, 6:45 pm, cesarnda <[EMAIL PROTECTED]> wrote: > ... >> result = [] > ... >> result.append(n) >> > ... >> if I compile in the notebook I get a html file showing me the >> following lines in yellow: >> >> def primes(int kmax): >> result = [] >> result.append(n) >> return result >> >> how can I modify this example to avoid the yellow lines? >> > As other people pointed out, there is not much hope for the "def" > and > the "return" line. >> > But wouldn't it be possible to do > cdef list result = [] >> Yep, you could do this. The resulting C code calls PyList_New(0) which is the fastest way to make a list. >> > And isn't there a quick, dirty and potentially unsafe way of > appending > to a list? >> Since it knows result is a list (due to the cdef above), it uses PyList_Append, the fastest way to append to a list. >> > Or at least for assigning a value to some list entry? I > think I have seen it somewhere, but I don't remember the name. >> Yep. Currently it calls __Pyx_SetItemInt which does an inline runtime boundscheck and check for a list, and if it's OK uses a macro to reset the specified entry right there. We could (should) optimize this in the case it already knows it's a list, but with good branch prediction it's probably within 5% of as fast as it could be period. >> - Robert > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Using sage to find point on a line a given distance from circle in 3D
Maybe I don't understand the question exactly. Consider the circle x^2+y^2=1, z=0, and the set S of all points at a small distance d, say d near 1/100, from this circle. I think that is a torus, isn't it? You want a symbolic equation (ie, a function of d) for the points in the intersection of this torus with a line? Just guessing, I would imagine this could depend on d in a complicated way, as when d is small you could have 0, 1, 2, 3, or 4 solutions, but when d is large, it seems to me you could have 0, 1 or 2 solutions. Maybe it's not so simple? On Fri, Sep 26, 2008 at 11:46 PM, Eugene Jhong <[EMAIL PROTECTED]> wrote: > > Newbie to sage - trying to find a point on a line in 3D that is a > specified distance from a circle (the line is not coplanar with the > circle). Here's what I've inputed into sage: > > var("line_dir_x line_dir_y line_dir_z line_p_x line_p_y line_p_z > cent_x cent_y cent_z norm_x norm_y norm_z u radius length") > line_dir = vector([line_dir_x, line_dir_y, line_dir_z]) # direction > of line > line_p = vector([line_p_x, line_p_y, line_p_z]) # point on > the line > cent = vector([cent_x, cent_y, cent_z]) # center > of circle > norm = vector([norm_x, norm_y, norm_z])# normal to > plane of circle > p = line_p + u * line_dir > diff0 = p - cent > dist = diff0.dot_product(norm) > diff1 = diff0 - dist * norm > sqr_len = diff1.dot_product(diff1) > closest_point1 = cent + (radius/sqrt(sqr_len))*diff1 > diff2 = p - closest_point1 > eq = length**Integer(2) == diff2.dot_product(diff2) > solve([eq], u) > > Here's what eq looks like: > > rleg_len^2 == (-radius*(-norm_z*(norm_z*(line_dir_z*u + line_p_z - > cent_z) + norm_y*(line_dir_y*u + line_p_y - cent_y) + > norm_x*(line_dir_x*u + line_p_x - cent_x)) + line_dir_z*u + line_p_z - > cent_z)/sqrt((-norm_z*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_z*u + line_p_z - cent_z)^2 + (- > norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)^2 + (- > norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)^2) + > line_dir_z*u + line_p_z - cent_z)^2 + (-radius*(- > norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)/sqrt((- > norm_z*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_z*u + line_p_z - cent_z)^2 + (- > norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)^2 + (- > norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)^2) + > line_dir_y*u + line_p_y - cent_y)^2 + (-radius*(- > norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)/sqrt((- > norm_z*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_z*u + line_p_z - cent_z)^2 + (- > norm_y*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_y*u + line_p_y - cent_y)^2 + (- > norm_x*(norm_z*(line_dir_z*u + line_p_z - cent_z) + > norm_y*(line_dir_y*u + line_p_y - cent_y) + norm_x*(line_dir_x*u + > line_p_x - cent_x)) + line_dir_x*u + line_p_x - cent_x)^2) + > line_dir_x*u + line_p_x - cent_x)^2 > > I try to do the solve but it doesn't seem to terminate after several > hours. Just looking for any pointers about finding an analytical > solution to this seemingly simple problem. > > > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Dimensional Analysis
Is there an easy way to do dimensional analysis with sagemath? --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Dimensional Analysis
revx wrote: > Is there an easy way to do dimensional analysis with sagemath? > What do you mean by "dimensional analysis"? Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Bug in plot?
On Sep 26, 4:07 pm, "Mike Hansen" <[EMAIL PROTECTED]> wrote: > Hi Jason, > > On Fri, Sep 26, 2008 at 9:05 AM, Jason Bandlow <[EMAIL PROTECTED]> wrote: > > A student of mine noticed the following and it looks like a bug to me > > (at least with the documentation). > > This was a regression caused by the reworking of plot.py in 3.1.2. > I've added a patch athttp://trac.sagemath.org/sage_trac/ticket/4201 > which fixes so things so that the old behavior works. > > --Mike You may want to see http://trac.sagemath.org/sage_trac/ticket/4099 for reference. I removed documentation for .options and .reset for several plot related functions, since I assumed these features were gone and not coming back. The patch was merged into 3.1.3.alpha0 Regards, JM --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Bug in plot?
Hi Jason M., On Fri, Sep 26, 2008 at 10:58 PM, Jason Merrill <[EMAIL PROTECTED]> wrote: > You may want to see http://trac.sagemath.org/sage_trac/ticket/4099 for > reference. I removed documentation for .options and .reset for > several plot related functions, since I assumed these features were > gone and not coming back. The patch was merged into 3.1.3.alpha0 The patch at 4201 adds the features and the documentation back :-) Thanks for keeping an eye open. --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Bug in plot?
On Sep 27, 2:02 am, "Mike Hansen" <[EMAIL PROTECTED]> wrote: > The patch at 4201 adds the features and the documentation back :-) > Thanks for keeping an eye open. Likewise :-). Guess if I had read your ticket, I would have seen that you were already on top of it. JM --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---