Comparing "diff" in Sagemath and Sympy

223 Views Asked by At

I am currently testing two programs of symbolic computation, one written in Sage and one in Sympy, which do similar computations. After running both of them, I found that the one written in Sympy is slower in a part of the code that involves making many derivatives.

I would like to see how the source code for the "diff" function is in both Sympy and Sage to compare them, and I found these definitions:

However, these do not look like source code and more like documentation about how to use them.

Is there any way that I could see the source code that is inside both functions? Maybe the performance difference of both languages has another origin, but I wanted to check this first.

PD: Sorry if this question doesn't fit the tags, but I think this is more a mathematical question (how is the derivative algorithm defined in both languages) rather than a programming question.

1

There are 1 best solutions below

0
On BEST ANSWER

It is source code. The (long!) parts between """ are documentation strings, but if you ignore them, you find the actual program code. For example, in sympy:

def diff(f, *symbols, **kwargs):
    """

    [ --- Ignore all this stuff! --- ]

    """
    if hasattr(f, 'diff'):
        return f.diff(*symbols, **kwargs)
    kwargs.setdefault('evaluate', True)
    return _derivative_dispatch(f, *symbols, **kwargs)