On Mon, Jul 21, 2008 at 8:27 PM, donu <[EMAIL PROTECTED]> wrote: > > I've been trying to continue learning Sage. This morning I translated > another of my scripts from Maple. This computes Hodge numbers of > complete intersections in projective space using a formula of > Hirzebruch. My first goal was to make it logically correct, and I > think it is. But now I need to worry about efficiency. The problem is > that this is generating huge polynomial expressions which seem to be > overwhelming Maxima running inside Sage for moderately large examples. > (Maple seems to be OK with these examples.) > A typical error log looks like this: > --------------------------------------- > Traceback (most recent call last): > File "/Applications/local/lib/python2.5/site-packages/sympy/ > plotting/", line 1, in <module> > > File "/Users/donu/.sage/sage_notebook/worksheets/admin/1/code/ > 11.py", line 104, in hodge > return hodge1(degs, n-len(degs)) > File "/Users/donu/.sage/sage_notebook/worksheets/admin/1/code/ > 11.py", line 153, in hodge1 > nexth = htemp.coeff(x,i).coeff(y,level-i) > File "/Applications/local/lib/python2.5/site-packages/sage/calculus/ > calculus.py", line 2660, in coeff > return self.parent()(self._maxima_().coeff(x, n)) > File "/Applications/local/lib/python2.5/site-packages/sage/calculus/ > calculus.py", line 1134, in _maxima_ > return RingElement._maxima_(self, maxima) > File "sage_object.pyx", line 316, in > sage.structure.sage_object.SageObject._maxima_ (sage/structure/ > sage_object.c:2879) > File "sage_object.pyx", line 247, in > sage.structure.sage_object.SageObject._interface_ (sage/structure/ > sage_object.c:1886) > File "/Applications/local/lib/python2.5/site-packages/sage/calculus/ > calculus.py", line 5078, in _maxima_init_ > return '(%s) %s (%s)' % (ops[0]._maxima_init_(), > ... > File "/Applications/local/lib/python2.5/site-packages/sage/calculus/ > calculus.py", line 5078, in _maxima_init_ > return '(%s) %s (%s)' % (ops[0]._maxima_init_(), > RuntimeError: maximum recursion depth exceeded > -------------------------------------- > I guess one solution would be explicitly call Singular which should be > able handle these kinds of calculations more gracefully that Maxima. > Another solution would be to trim the polynomials as I go along, by > throwing away high degree terms. Does anyone know a good way to do > this in Sage? In Maple I would do something like this for p(x,y) > > trim := 0 > for term in op(p) do > if (degree(term, x) + degree(term,y) <= N) then > trim := trim + term > end if > end do > > But I'm not sure it translates. >
Sage has extremely powerful native support for multivariate polynomials, which completely avoids maxima. It uses Singular in library mode and is very robust. However, you don't get it by just using var and the symbolic calculus stuff in Sage. You have to use the PolynomialRing function. E.g., sage: R.<x,y> = PolynomialRing(QQ,2) sage: f = x^3 + y^5 sage: g = f^2 sage: g y^10 + 2*x^3*y^5 + x^6 sage: g.truncate(x,5) y^10 + 2*x^3*y^5 See http://sagemath.org/doc/html/ref/node289.html William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
