[sage-support] Re: Numerical methods for solving matrix equations
William Stein wrote: > On Thu, Jun 18, 2009 at 8:31 PM, Ethan Van Andel wrote: >> Does sage have a way to use a numeric method (such as Jacobi, or Gauss- >> Sidel) to solve matrix equations of the form A*x = b? (CDF matrices by >> the way). the A.solve_right(b) method is too slow. >> >> Thanks, >> Ethan > > Here is an example of how to convert back/forth to numpy to solve A*x > = b very quickly. Below we do this with A a 1000x1000 matrix, and it > takes about a half second. It would be *great* if somebody made it > so this would work in Sage automatically without having to explicitly > use numpy like I've done before. But for you, I bet this is a minor > inconvenience. > > sage: n = 1000 > sage: a = random_matrix(CDF,n); v = random_matrix(CDF,n,1) > sage: aa = a.numpy(); vv = v.numpy() > sage: import numpy > sage: time ww = numpy.linalg.solve(aa, vv) > Time: CPU 0.57 s, Wall: 0.41 s > sage: w = matrix(CDF, ww) > sage: max([abs(z) for z in a*w - v]) > 5.46740430707e-12 + 8.431033649e-13*I Gosh, this is embarrassing... I just looked at the code for the CDF matrices. The *solve_left* function uses almost the exact same code as you did, William, and takes the same amount of time. Now why is it solve_left? I have no idea (but it's no doubt my fault!). solve_right, of course, takes a lot more time because it copies the entire matrix to transpose it before solving the system (but then it solves the wrong system, since solve_left should be solve_right!) I guess one thing is the saving grace---a CDF matrix's solve_left function is documented as solving the system Ax=b. So, right now things are messed up. I'll detail the fix on the ticket (and maybe even just post a patch). To answer the original poster, here is William's session and comparable code (that is just as fast!): Williams session on my computer: sage: n=1000 sage: a=random_matrix(CDF,n); v=random_matrix(CDF,1,n)[0] sage: aa=a.numpy(); vv=v.numpy() sage: import numpy sage: time www=numpy.linalg.solve(aa,vv) CPU times: user 1.42 s, sys: 0.08 s, total: 1.50 s Wall time: 2.89 s sage: w=vector(CDF,www) sage: max(abs(z) for z in a*w-v) 1.95733512586e-12 Using the current (wrongly-named!) functions: sage: time w=a.solve_left(v) CPU times: user 2.08 s, sys: 0.22 s, total: 2.30 s Wall time: 7.59 s sage: time w=a.solve_left(v) CPU times: user 1.54 s, sys: 0.07 s, total: 1.61 s Wall time: 2.32 s sage: max(abs(z) for z in a*w-v) 2.67581211819e-12 Jason P.S. The solve_left_lu function is still probably messed up too... > > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: API up
The gif link is broken. Tries to use a private address. 192.168.1.101 That doesn't work with my computer, of course. I don't have IE8 so I can't comment on that. On Thu, Jun 18, 2009 at 4:13 PM, David Joyner wrote: > > On Thu, Jun 18, 2009 at 2:38 PM, Mikie wrote: >> >> How fast was it and did it work with IE8? > > > It was fast for me but sorry, I don't use windows. > > >> >> On Jun 18, 11:37 am, David Joyner wrote: >>> Cool! >>> >>> >>> >>> On Thu, Jun 18, 2009 at 12:46 PM, Mikie wrote: >>> >>> > I have my API running on a host. Not real pretty yet, but it seems to >>> > work. >>> > Please, test. >>> >http://pirsqrt.com:7316 >>> > Thanx- Hide quoted text - >>> >>> - Show quoted text - >> > >> > > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: API up
On Thu, Jun 18, 2009 at 2:38 PM, Mikie wrote: > > How fast was it and did it work with IE8? It was fast for me but sorry, I don't use windows. > > On Jun 18, 11:37 am, David Joyner wrote: >> Cool! >> >> >> >> On Thu, Jun 18, 2009 at 12:46 PM, Mikie wrote: >> >> > I have my API running on a host. Not real pretty yet, but it seems to >> > work. >> > Please, test. >> >http://pirsqrt.com:7316 >> > Thanx- Hide quoted text - >> >> - Show quoted text - > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: API up
Do you Skype. Use my e-mail. On Jun 18, 1:32 pm, Marshall Hampton wrote: > Works fine, very fast on Firefox 2. I am very interested in this sort > of effort, if you have a chance to share your thoughts on what you > have learned doing this I would greatly appreciate it. > > -M. Hampton > > On Jun 18, 1:38 pm, Mikie wrote: > > > > > How fast was it and did it work with IE8? > > > On Jun 18, 11:37 am, David Joyner wrote: > > > > Cool! > > > > On Thu, Jun 18, 2009 at 12:46 PM, Mikie wrote: > > > > > I have my API running on a host. Not real pretty yet, but it seems to > > > > work. > > > > Please, test. > > > >http://pirsqrt.com:7316 > > > > Thanx- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: bug: no local scope for symbolic variables
On Thu, Jun 18, 2009 at 12:29 AM, Robert Bradshaw wrote: > > On Jun 17, 2009, at 9:21 AM, William Stein wrote: > >> 2009/6/17 Robert Bradshaw : >>> >>> On Jun 17, 2009, at 3:05 AM, Utpal Sarkar wrote: >>> Thanks for the replies. I noticed something funny: if you call x = var("X") in some scope, it is X that is injected into the global scope, not x. In fact I thought that the argument was merely a print name. >>> >>> var("X") is what makes the variable, there's nothing special about >>> assignment. For example, if I wrote >>> >>> sage: x = var("X") + 1 >>> >>> then x would have the value X + 1, and as a side effect, X would be >>> injected into the global scope. This seems like a surprising artifact >>> to many people, and is certainly not like anything Python does. Was >>> there a strong justification for doing this? >> >> If I remember correctly: >> >> 1. The symbolic calculus code is not aimed at experience Python >> programmers or users. >> >> 2. It is very nice for var('x,y,z,theta') to work, and to not require >> the user to type: >> x,y,z,theta = var('x,y,z,theta') >> >> 3. Having var at all is a compromise -- many symbolic calculus users >> would prefer for undefined vars to just "magically" be defined, as is >> done in Mathematica, Maple, Maxima, Axiom (?), etc. > > That's enough justification for me. I'm still in favor of an optional > "global" keyword to the var function that was brought up earlier. in sympy we use symbols() for just returning the symbols and var() that calls (and returns) symbols *and* injects them to the global space. O. --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Numerical methods for solving matrix equations
2009/6/18 Ethan Van Andel : > > That worked beautifully, thanks for the fast response. Making CDF's solve_right faster is now: http://trac.sagemath.org/sage_trac/ticket/6358 William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: API up
Works fine, very fast on Firefox 2. I am very interested in this sort of effort, if you have a chance to share your thoughts on what you have learned doing this I would greatly appreciate it. -M. Hampton On Jun 18, 1:38 pm, Mikie wrote: > How fast was it and did it work with IE8? > > On Jun 18, 11:37 am, David Joyner wrote: > > > Cool! > > > On Thu, Jun 18, 2009 at 12:46 PM, Mikie wrote: > > > > I have my API running on a host. Not real pretty yet, but it seems to > > > work. > > > Please, test. > > >http://pirsqrt.com:7316 > > > Thanx- Hide quoted text - > > > - Show quoted text - --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Inheritance from sage.symbolic.expression.Expression
Dear Burcin, After thorough tests, your patch works pretty well ! I have just encountered a problem with pickling (and thus the save function). There is a workaround by using the __repr__ function for file saving but this requires parsing after loading. Here is the behavior of save in sage.4.0.1 with the patch applied : -- | Sage Version 4.0.1, Release Date: 2009-06-06 | | Type notebook() for the GUI, and license() for information.| -- sage: class esub(Expression): : def __init__(self, parent, val): : Expression.__init__(self, parent, val) : sage: a=esub(SR,x) sage: a x sage: save(x,"file") sage: save(a,"file") --- PicklingError Traceback (most recent call last) /home/fresseng/.sage/temp/nix.sciences.univ_metz.fr/24993/ _home_fresseng__sage_init_sage_0.py in () /usr/local/src/sage-4.0.1/local/lib/python2.5/site-packages/sage/ structure/sage_object.so in sage.structure.sage_object.save (sage/ structure/sage_object.c:6832)() /usr/local/src/sage-4.0.1/local/lib/python2.5/site-packages/sage/ structure/sage_object.so in sage.structure.sage_object.SageObject.save (sage/structure/sage_object.c:1866)() /usr/local/src/sage-4.0.1/local/lib/python2.5/site-packages/sage/ structure/sage_object.so in sage.structure.sage_object.SageObject.dumps (sage/structure/ sage_object.c:2080)() PicklingError: Can't pickle : attribute lookup __main__.esub failed In my opinion, this should work. Am I wrong ? Is there a special method to implement in the extension class esub ? Thanks for your help ! Nicolas On 12 juin, 11:22, Burcin Erocal wrote: > Hi Nicolas, > > On Fri, 12 Jun 2009 02:09:08 -0700 (PDT) > > Nicolas wrote: > > Just one quick question about patches, I have just changed the > > expression.pyx file and ran another make (which took not so much > > time). But it does not seem to work. Is this simple way of applying > > patch enough or do I have to go through the mercurial system ? > > You need to do > > ./sage -br > > From your other message: > > > I will try out your patch. Why do you say that does not solve my > > problem ? > > You'll see that whenever you perform arithmetic on the new objects, > you'll end up with Expression's again. > > < assuming the class esub was defined as in my previous message > > sage: var('x,y,z') > (x, y, z) > sage: t = x * y^z > sage: u = esub(SR, t) > sage: u > y^z*x > sage: type(u) > > sage: type(u*u) > > > Let's see how far you get with the patch. I'll try to see if there is > a simple fix to make Expression behave well w.r.t. object oriented > design. > > Cheers, > Burcin --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Numerical methods for solving matrix equations
That worked beautifully, thanks for the fast response. --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: API up
How fast was it and did it work with IE8? On Jun 18, 11:37 am, David Joyner wrote: > Cool! > > > > On Thu, Jun 18, 2009 at 12:46 PM, Mikie wrote: > > > I have my API running on a host. Not real pretty yet, but it seems to > > work. > > Please, test. > >http://pirsqrt.com:7316 > > Thanx- Hide quoted text - > > - Show quoted text - --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Numerical methods for solving matrix equations
On Thu, Jun 18, 2009 at 8:31 PM, Ethan Van Andel wrote: > > Does sage have a way to use a numeric method (such as Jacobi, or Gauss- > Sidel) to solve matrix equations of the form A*x = b? (CDF matrices by > the way). the A.solve_right(b) method is too slow. > > Thanks, > Ethan Here is an example of how to convert back/forth to numpy to solve A*x = b very quickly. Below we do this with A a 1000x1000 matrix, and it takes about a half second. It would be *great* if somebody made it so this would work in Sage automatically without having to explicitly use numpy like I've done before. But for you, I bet this is a minor inconvenience. sage: n = 1000 sage: a = random_matrix(CDF,n); v = random_matrix(CDF,n,1) sage: aa = a.numpy(); vv = v.numpy() sage: import numpy sage: time ww = numpy.linalg.solve(aa, vv) Time: CPU 0.57 s, Wall: 0.41 s sage: w = matrix(CDF, ww) sage: max([abs(z) for z in a*w - v]) 5.46740430707e-12 + 8.431033649e-13*I --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Numerical methods for solving matrix equations
Does sage have a way to use a numeric method (such as Jacobi, or Gauss- Sidel) to solve matrix equations of the form A*x = b? (CDF matrices by the way). the A.solve_right(b) method is too slow. Thanks, Ethan --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: API up
Cool! On Thu, Jun 18, 2009 at 12:46 PM, Mikie wrote: > > I have my API running on a host. Not real pretty yet, but it seems to > work. > Please, test. > http://pirsqrt.com:7316 > Thanx > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] API up
I have my API running on a host. Not real pretty yet, but it seems to work. Please, test. http://pirsqrt.com:7316 Thanx --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: build errors for sage 4.0.1 on Fedora 11
On Wed, Jun 17, 2009 at 6:44 PM, gerhard wrote: > > for now, I just bandaided the code by adding > const_cast expressions. > -gerhard > I would still really like to know if you still have this problem with sage-4.0.2.rc3: http://sage.math.washington.edu/home/wstein/farm/src/ Since if so, we'll have to fix it in our version, report the problem to the Singular group, etc. William > > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: factor
Hi William, On Jun 18, 12:14 pm, William Stein wrote: ... > You can also do > > sage: R. = ZZ[] > > which doesn't look like a double definition. That's what I usually do. Sure. But when you see Mikie's post from June 17, this is what he did. The only problem was (as pointed out by other people) that it can't be used in a python script, due to the missing Sage preparser. Cheers, Simon --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: factor
On Thu, Jun 18, 2009 at 11:24 AM, John Cremona wrote: > > > > On Jun 17, 5:34 pm, William Stein wrote: >> 2009/6/17 Robert Bradshaw : >> >> >> >> > On Jun 17, 2009, at 4:05 AM, John Cremona wrote: >> >> >> I think is is easier, both on the eye and for a beginner to >> >> understand: >> >> >> sage: x = polygen(ZZ) >> >> sage: f = 2*x**2 - x >> >> sage: f.factor() >> >> x * (2*x - 1) >> >> > Perhaps. I like the R[var] notation because it's a direct translation >> > of the mathematical notation. >> >> I love the R[var] notation too. I remember making it up and being very >> pleased. > > Sure. However you cannot do R=ZZ[t] but must do R=ZZ['t'], and then > do something else to get the variable t to be assigned to the variable > which prints as 't'. that means either R.=ZZ['t'] (which to a > mathematician looks like double definition), You can also do sage: R. = ZZ[] which doesn't look like a double definition. That's what I usually do. William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: factor
On Jun 17, 5:34 pm, William Stein wrote: > 2009/6/17 Robert Bradshaw : > > > > > On Jun 17, 2009, at 4:05 AM, John Cremona wrote: > > >> I think is is easier, both on the eye and for a beginner to > >> understand: > > >> sage: x = polygen(ZZ) > >> sage: f = 2*x**2 - x > >> sage: f.factor() > >> x * (2*x - 1) > > > Perhaps. I like the R[var] notation because it's a direct translation > > of the mathematical notation. > > I love the R[var] notation too. I remember making it up and being very > pleased. Sure. However you cannot do R=ZZ[t] but must do R=ZZ['t'], and then do something else to get the variable t to be assigned to the variable which prints as 't'. that means either R.=ZZ['t'] (which to a mathematician looks like double definition), or t = ZZ['t'].gen(0) which looks rather less mathematical (and does not end up giving the ring a name). Why can't these computers just know what we mean! > > > Note the default variable name: > > > sage: t = polygen(ZZ) > > sage: t > > x > > yes, that's good to point out. To make it t: > > sage: t = polygen(ZZ,'t') > sage: t > t > Ahah! I think I have only ever used x, so I had not noticed that John Cremona > William --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: error finding the units of a number field
I only just saw this thread. I wrote the units functionality (of course pari does the hard work); I think Francis Clarke made some changes so that things work for relative extensions too. [If anything for relative extensions works properly in Sage, it is usually Francis who takes the credit]. As this has been fixed in 4.0.2 which will be released soon, I suggest that mac8090 waits. I would not recommend picking a single patch and expecting it to work on its own as patches tend to depend on one another. Anyway, neither bonzerpotato nor mac8090 ever said which version they were running (that I can see), which is surely a normal prerequisite for getting any help at all! John Cremona On Jun 17, 8:22 pm, Craig Citro wrote: > Hi, > > > thanks! however, not quite there - how do I get the units in terms of > > q? > > So I just tried this in sage 4.0.2.rc2, and here's what I got: > > sage: K. = NumberField(x^2+2) ; K > Number Field in q with defining polynomial x^2 + 2 > sage: B. = K[] > sage: A. = K.extension(x^3+(q^3)*x^2+(2*q^2)*x-3*q) > sage: A.unit > A.unit_group A.unit_ideal A.units > sage: A.unit_group() > Unit group with structure C2 x Z x Z of Number Field in c with > defining polynomial x^3 - 2*q*x^2 - 4*x - 3*q over its base field > sage: A.units() > [q*c - 1, (-405*q - 1845)*c^2 + (674*q - 3960)*c - 2058*q - 1465] > > Is that what you were looking for? You could also do this (continuing > the above session): > > sage: U = A.unit_group() > sage: U.gens() > [-1, q*c - 1, (-405*q - 1845)*c^2 + (674*q - 3960)*c - 2058*q - 1465] > > To be honest, I haven't thought at all about what new patches made > this work (as the .units() call clearly failed before) -- but I bet > the patch was by either Nick Alexander or John Cremona, so maybe one > of them can pipe in and say "oh, I fixed that" to earn their fame and > glory. ;) > > -cc --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---