Hi Francois, On Mon, 28 Sep 2009 20:28:46 +0200 Francois Maltey <fmal...@nerim.fr> wrote:
> If I am right, the symbolic manipulations of Sage come from the > (py)ginac librairies. Yes, we use pynac, which is derived from ginac to replace the numeric types with python objects. It is a good idea to read the ginac documentation to find out more about pynac data structures, especially the tutorial: http://www.ginac.de/tutorial/ Ginac is very well documented, this was one of the reasons we chose to base the new symbolics on it. :) > In ginac documentation I find very intersting functions for my use of > expressions : > > is_a<numeric> > is_a<real> > is_a<rational> > > There are about 30 tests for possible types. <snip> > Is it possible to call theses functions from sage ? or must I insert > a new "module" in sage ? You can call these functions only from cython, since these are functions in a c++ library. It's not hard to add support for these, perhaps as ._is_numeric() or ._is_real() methods of symbolic expressions. One way to do that is - to look in sage/libs/ginac/decl.pxi to see if the function you want is declared so it can be used in cython. Search for "is_a_" and you'll see several declarations scattered through the file. If what you want isn't listed, just add it imitating one of the previous ones. I suggest adding the new ones after the comment "# more is_a tests " on line 195. - then go to sage/symbolic/expression.pyx and add a new method for the property you are testing for. It would look like: def _is_numeric(self): return is_a_numeric(self._gobj) - save your changes and rebuild Sage by doing "sage -br" - now if you do "x.<tab>" you should see your new function On another note, I have a very experimental patch that returns the real python object after calls to methods of symbolic expressions, instead of the python object wrapped in a sage.symbolic.expression.Expression. For example: sage: t = 2*x sage: t.operands()[1] 2 sage: type(t.operands()[1]) <type 'sage.rings.integer.Integer'> Note that now the command above returns sage: type(t.operands()[1]) <type 'sage.symbolic.expression.Expression'> With this patch, you could just test for the type of the coefficient, as you would normally test anywhere else in Sage, using "in ZZ". My motivation for this change was to get this working: sage: type(sin(x).subs(x=float(.5))) <type 'float'> I put this patch here: http://sage.math.washington.edu/home/burcin/pynac/return_numeric_as_pyobject.2.patch Any comments are welcome. Cheers, Burcin --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---