Your confusions here relate to Python's syntax.

simplify is defined by the keyword argument to the rref() function:

def rref(self, iszerofunc=_iszero, simplify=False, pivots=True,
normalize_last=True):

The default is False, unless the user specifies simplify=<something
else>, where <something else> should be a function.

Actually this code is not written in a very idiomatic way. The default
False implies that no simplification should happen, but this is not
the case. A better way to write this code would be

simpfunc = simplify or _simplify

with the function definition as

def rref(self, iszerofunc=_iszero, simplify=None, pivots=True,
normalize_last=True):

The isinstance(simplify, FunctionType) type check is not necessary.

> why simplify is imported as _simplify as well as nsimplify? I mean what is 
> the need of both?

The simplify() function is imported as _simplify because otherwise it
would not be accessible in rref(), because the name "simplify" is
already used by the keyword argument.

nsimplify() is a separate function. The syntax

from sympy.simplify import simplify as _simplify, nsimplify

should be read as

from sympy.simplify import (simplify as _simplify), nsimplify # This
is not valid syntax, but this is how the precedence works

or equivalently,

from sympy.simplify import simplify as _simplify
from sympy.simplify import nsimplify

Aaron Meurer

On Tue, Oct 30, 2018 at 1:34 PM Ruchit Vithani <[email protected]> wrote:
>
> I was looking code of rref() function of matrixes.py, In this function, there 
> is a function variable defined as
>
> simpfunc = simplify if isinstance(
> simplify, FunctionType) else _simplify
>
> Why here it is checked that simplify is a FunctionType, which other type does 
> the simplify word has?
> Also at the beginning of the matrices.py following is imported
>
> from sympy.simplify import simplify as _simplify, nsimplify
>
> why simplify is imported as _simplify as well as nsimplify? I mean what is 
> the need of both?
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/8cf34aa0-bdaa-4fb3-a0b3-cdccfb731206%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BTXZvHgomvWuV58nzs6z0EyBTzfvz_B%3D5esgoLuNN%3DgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to