Hej All,

I was doing some work on http://trac.sagemath.org/sage_trac/ticket/9094.
In trying to do it the nice way (i.e. avoiding unnessery double code
by putting the code in a common base class) I ran into trouble. The
core of all problems seems to be with real_lazy. What goes wrong is
that they add functions to a class in sage.rings.real_lazy in a way
that I don't understand and in a way that seems not very compatible
with good object oriented coding conventions. Below you what happens
if you would want to see the source code of the sqrt function of
elements of the Real Lazy Field (it returns an error). So the sqrt
function is actually there.

Now adding the sqrt function to RingElement (from which LazyWrapper
eventually also derives) breakes the construction by which the sqrt
function is added and now a.sqrt() becomes the function defined for
RingElement. If the sqrt() function of LazyWrapper was added through
normal class extensions there would have been no problem since the
very general sqrt() function would get overwritten and everything
would work as before. Does anyone with a bit more understanding of
python then me know what is going on in sage.rings.real_lazy and most
importand, is it possible to make the mechanism by which LazyWrapper
adds the sqrt function overwrite an already existing sqrt() function?

In sage 4.4.4 without any changes:

sage: a=RLF(3)
sage: a.sqrt??
Error getting source: could not find class definition
Type:           LazyNamedUnop
Base Class:     <type 'sage.rings.real_lazy.LazyNamedUnop'>
String Form:    1.732050807568878?
Namespace:      Interactive
File:           /Applications/sage/local/lib/python2.6/site-packages/sage/rings/
real_lazy.so
Definition:     a.sqrt(self, *args)
Docstring [source file open failed]:
    x.__init__(...) initializes x; see x.__class__.__doc__ for
signature

Call def:       a.sqrt(self, *args)

Call docstring:

       TESTS:
          sage: a = RLF(32) sage: a.log(2) 5 sage: float(a.log(2)) 5.0

       What is going on here in the background is
          sage: from sage.rings.real_lazy import LazyNamedUnop sage: b
=
          LazyNamedUnop(RLF, a, 'log') sage: b(2) 5 sage:
b(2)._extra_args
          (2,)








In sage 4.4.4 with a sqrt method defined on RingElement

sage: a=RLF(3)
sage: a.sqrt??

Type:           builtin_function_or_method
Base Class:     <type 'builtin_function_or_method'>
String Form:    <built-in method sqrt of
sage.rings.real_lazy.LazyWrapper object at 0x10c93e050>
Namespace:      Interactive
Definition:     a.sqrt(self, extend=True, all=False, name=None)
Source:
    def sqrt(self, extend = True, all = False, name=None ):
        """
        It computes the square root.

        INPUT:

        -  ``extend`` - Whether to make a ring extension containing a
square root if self is not a square (default: True)

etc. etc. etc.

-- 
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

Reply via email to