[sage-support] Controlling output from ``product_on_basis''
Hello sage-suport community, I am working with a CombinatorialFreeModule with a multiplication defined using the product_on_basis method. Inside the call of product_on_basis I actually do multiplications in the algebra so that it becomes something of a recursive function. After the outermost call originating from the user I would like to run an additional command to clean up and simplify the output, whereas right now it is run on every iteration, greatly slowing the calculation. Also the user might type an expression containing many multiplications and ideally the simplifying command would only be called after the final multiplication has been performed. Any thoughts on how to insert such a command? Thank you! -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
[sage-support] Re: Cython help
I sent a copy of my code and a few samples of what I would like to do with it to your gmail. Thanks for your help, Dylan On Apr 24, 1:48 pm, Mike Hansen wrote: > On Fri, Apr 24, 2009 at 1:40 PM, drupel wrote: > > Thanks Mike, > > Is it possible to do the symbolic computations with Cython? > > Yes, you can do them from within Cython, but it's not going to give > you the speed up that you might think / want. Making code faster is > almost entirely finding out exactly where all of the time is being > spent. > > > If not, I will wait until Sage 4.0 comes out and see what happens. > > If you send me your code (along with sample runs), I'll go through and > speed things up for you. That are optimizations that you can do by > just being conscious of data types and things like that. > > --Mike --~--~-~--~~~---~--~~ 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: Cython help
Thanks Mike, Is it possible to do the symbolic computations with Cython? If not, I will wait until Sage 4.0 comes out and see what happens. Dylan --~--~-~--~~~---~--~~ 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] Cython help
Hi all, I am new to Sage and I don't quite understand how to convert my code to cython code to speed up my program. I am doing a lot of symbolic manipulations and using the PolynomialRing object. Below I have some of my code so that you can see the types of manipulations I hope to speed up: Ring=PolynomialRing(ZZ,'q,t') q,t=Ring.gens() A=PolynomialRing(Ring,'x1,x1L,x1R,x2,x2L,x2R') x1,x1L,x1R,x2,x2L,x2R=A.gens() xnplus3=[] xnegn=[] zn=[] def qnumber(n): g(q,t)=(q^n-t^n)/(q-t) return g def qfactorial(n): prod(q,t)=1 for k in range(n): prod(q,t)=prod*qnumber(k+1) return prod def quantumBinomial(n,k): f(q,t)=factor(qfactorial(n)/(qfactorial(k)*qfactorial(n-k))) return f(q,q^(-1)) def L(x1x2_expr): f=x1x2_expr.substitute({x1:x1L,x2:x2L}) return f def R(x1x2_expr): f=x1x2_expr.substitute({x1:x1R,x2:x2R}) return f def x_nplus3(n): s=X(-n-1,n+2) #x1^(-n-1)*x2^(n+2) for p in range(n+1): for r in range(n+1-p): b1=quantumBinomial(n-r,p) b2=quantumBinomial(n+1-p,r) s=s+b1*b2*X(2*p-n-1,2*r-n) return s def commute(LR_expr): Sum=0 Coeffs=LR_expr.coeffs(x2L) for Term in Coeffs: Term[0]=Term[0].substitute({x1L:x1,x1R:q^(-Term[1]) *x1,x2R:x2}) Sum=Sum+Term[0]*x2^(Term[1]) Coeffs=Sum.coeffs(x1) Sum=0 for Term in Coeffs: coeffs=Term[0].coeffs(x2) for term in coeffs: p=q^(-term[1]*Term[1]/2) adj_qterm=term[0]/p qcoeffs=adj_qterm.coeffs(q) new_qterm=0 for qterm in qcoeffs: if qterm[1]>=0: new_qterm=new_qterm+qterm[0]*q^(qterm[1]) if qterm[1]<0: new_qterm=new_qterm+qterm[0]*t^(-qterm[1]) Sum=Sum+factor(new_qterm)*p*x1^(Term[1])*x2^(term[1]) return Sum.substitute({t:q^(-1)}) I am hoping to get a few pointers and suggestions for making my code compatible with cython. Thank you for your time. Dylan --~--~-~--~~~---~--~~ 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: A problem with the simplify command
Thanks for the help! The expression that I had was a result of a previous computation and I did not realize that I had to expand the expression and the simplify command would not multiply then cancel common terms. On Apr 23, 9:38 pm, Minh Nguyen wrote: > On Fri, Apr 24, 2009 at 4:37 AM, Minh Nguyen wrote: > > Hi Dylan, > > > On Fri, Apr 24, 2009 at 4:32 AM, drupel wrote: > > >> Hi all: > >> I am using Sage Version 3.4, Release Date: 2009-03-11. I asked Sage > >> to simplify the following expression: > >> -q^(5/2)*(q^2*x2^4 + q*x2^2) + q^(9/2)*x2^4 + q^(3/2)*(q^2 + 1) > >> *x2^2 + sqrt(q) > >> by calling the simplify command: > >> simplify(-q^(5/2)*(q^2*x2^4 + q*x2^2) + q^(9/2)*x2^4 + q^(3/2)* > >> (q^2 + 1)*x2^2 + sqrt(q)) > >> but the output was exactly the same as what I put in. In my code > >> ahead of this I have > >> R=PolynomialRing(ZZ,'q') > >> var('q') > >> Any suggestions would be much appreciated. > > > Try this: > > Should be this > > [mv...@sage ~]$ sage > -- > | Sage Version 3.4.1, Release Date: 2009-04-21 | > | Type notebook() for the GUI, and license() for information. | > -- > sage: q, x2 = var("q, x2") > sage: simplify(expand(-q^(5/2)*(q^2*x2^4 + q*x2^2) + q^(9/2)*x2^4 + > q^(3/2)*(q^2 + 1)*x2^2 + sqrt(q))) > q^(3/2)*x2^2 + sqrt(q) > > Sorry about the noise. > > -- > Regards > Minh Van Nguyen --~--~-~--~~~---~--~~ 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] A problem with the simplify command
Hi all: I am using Sage Version 3.4, Release Date: 2009-03-11. I asked Sage to simplify the following expression: -q^(5/2)*(q^2*x2^4 + q*x2^2) + q^(9/2)*x2^4 + q^(3/2)*(q^2 + 1) *x2^2 + sqrt(q) by calling the simplify command: simplify(-q^(5/2)*(q^2*x2^4 + q*x2^2) + q^(9/2)*x2^4 + q^(3/2)* (q^2 + 1)*x2^2 + sqrt(q)) but the output was exactly the same as what I put in. In my code ahead of this I have R=PolynomialRing(ZZ,'q') var('q') Any suggestions would be much appreciated. Thanks, Dylan --~--~-~--~~~---~--~~ 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] factoring polynomials
I am hoping to be able to factor a single variable polynomial with positive coefficients onto factors that only involve positive coefficients. For example I would like to factor q^10+q^8+q^6+q^4+q^2+1 as (q^2 + 1)*(q^8+q^4+1) rather than (q^2 + 1)* (q^2 - q + 1)*(q^2 + q + 1)*(q^4 - q^2 + 1) as the factor command does. If possible I would _really_ like to have Sage give the first factorized form as (q+1/q)*(q^4+1+1/q^4)*q^5. Any suggestions? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---