def linsolve(system, *symbols):
    '\n    Solve system of N linear equations with M variables, which\n    means both under - and overdetermined systems are supported.\n    The possible number of solutions is zero, one or infinite.\n    Zero solutions throws a ValueError, where as infinite\n    solutions are represented parametrically in terms of given\n    symbols. For unique solution a FiniteSet of ordered tuple\n    is returned.\n\n    All Standard input formats are supported:\n    For the given set of Equations, the respective input types\n    are given below:\n\n    .. math:: 3x + 2y -   z = 1\n    .. math:: 2x - 2y + 4z = -2\n    .. math:: 2x -   y + 2z = 0\n\n    * Augmented Matrix Form, `system` given below:\n\n    ::\n\n              [3   2  -1  1]\n     system = [2  -2   4 -2]\n              [2  -1   2  0]\n\n    * List Of Equations Form\n\n    `system  =  [3x + 2y - z - 1, 2x - 2y + 4z + 2, 2x - y + 2z]`\n\n    * Input A & b Matrix Form (from Ax = b) are given as below:\n\n    ::\n\n         [3   2  -1 ]         [  1 ]\n     A = [2  -2   4 ]    b =  [ -2 ]\n         [2  -1   2 ]         [  0 ]\n\n    `system = (A, b)`\n\n    Symbols to solve for should be given as input in all the\n    cases either in an iterable or as comma separated arguments.\n    This is done to maintain consistency in returning solutions\n    in the form of variable input by the user.\n\n    The algorithm used here is Gauss-Jordan elimination, which\n    results, after elimination, in an row echelon form matrix.\n\n    Returns\n    =======\n\n    A FiniteSet of ordered tuple of values of `symbols` for which\n    the `system` has solution.\n\n    Please note that general FiniteSet is unordered, the solution\n    returned here is not simply a FiniteSet of solutions, rather\n    it is a FiniteSet of ordered tuple, i.e. the first & only\n    argument to FiniteSet is a tuple of solutions, which is ordered,\n    & hence the returned solution is ordered.\n\n    Also note that solution could also have been returned as an\n    ordered tuple, FiniteSet is just a wrapper `{}` around\n    the tuple. It has no other significance except for\n    the fact it is just used to maintain a consistent output\n    format throughout the solveset.\n\n    Returns EmptySet(), if the linear system is inconsistent.\n\n    Raises\n    ======\n\n    ValueError\n        The input is not valid.\n        The symbols are not given.\n\n    Examples\n    ========\n\n    >>> from sympy import Matrix, S, linsolve, symbols\n    >>> x, y, z = symbols("x, y, z")\n    >>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])\n    >>> b = Matrix([3, 6, 9])\n    >>> A\n    Matrix([\n    [1, 2,  3],\n    [4, 5,  6],\n    [7, 8, 10]])\n    >>> b\n    Matrix([\n    [3],\n    [6],\n    [9]])\n    >>> linsolve((A, b), [x, y, z])\n    {(-1, 2, 0)}\n\n    * Parametric Solution: In case the system is under determined, the function\n      will return parametric solution in terms of the given symbols.\n      Free symbols in the system are returned as it is. For e.g. in the system\n      below, `z` is returned as the solution for variable z, which means z is a\n      free symbol, i.e. it can take arbitrary values.\n\n    >>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n    >>> b = Matrix([3, 6, 9])\n    >>> linsolve((A, b), [x, y, z])\n    {(z - 1, -2*z + 2, z)}\n\n    * List of Equations as input\n\n    >>> Eqns = [3*x + 2*y - z - 1, 2*x - 2*y + 4*z + 2, - x + S(1)/2*y - z]\n    >>> linsolve(Eqns, x, y, z)\n    {(1, -2, -2)}\n\n    * Augmented Matrix as input\n\n    >>> aug = Matrix([[2, 1, 3, 1], [2, 6, 8, 3], [6, 8, 18, 5]])\n    >>> aug\n    Matrix([\n    [2, 1,  3, 1],\n    [2, 6,  8, 3],\n    [6, 8, 18, 5]])\n    >>> linsolve(aug, x, y, z)\n    {(3/10, 2/5, 0)}\n\n    * Solve for symbolic coefficients\n\n    >>> a, b, c, d, e, f = symbols(\'a, b, c, d, e, f\')\n    >>> eqns = [a*x + b*y - c, d*x + e*y - f]\n    >>> linsolve(eqns, x, y)\n    {((-b*f + c*e)/(a*e - b*d), (a*f - c*d)/(a*e - b*d))}\n\n    * A degenerate system returns solution as set of given\n      symbols.\n\n    >>> system = Matrix(([0,0,0], [0,0,0], [0,0,0]))\n    >>> linsolve(system, x, y)\n    {(x, y)}\n\n    * For an empty system linsolve returns empty set\n\n    >>> linsolve([ ], x)\n    EmptySet()\n\n    '
    if (not system):
        return S.EmptySet
    if (not symbols):
        raise ValueError('Symbols must be given, for which solution of the system is to be found.')
    if hasattr(symbols[0], '__iter__'):
        symbols = symbols[0]
    try:
        sym = symbols[0].is_Symbol
    except AttributeError:
        sym = False
    if (not sym):
        raise ValueError(('Symbols or iterable of symbols must be given as second argument, not type %s: %s' % (type(symbols[0]), symbols[0])))
    if isinstance(system, Matrix):
        (A, b) = (system[:, :(- 1)], system[:, (- 1):])
    elif hasattr(system, '__iter__'):
        if ((len(system) == 2) and system[0].is_Matrix):
            (A, b) = (system[0], system[1])
        if (not system[0].is_Matrix):
            (A, b) = linear_eq_to_matrix(system, symbols)
    else:
        raise ValueError('Invalid arguments')
    try:
        (sol, params, free_syms) = A.gauss_jordan_solve(b, freevar=True)
    except ValueError:
        return EmptySet()
    solution = []
    if params:
        for s in sol:
            for (k, v) in enumerate(params):
                s = s.xreplace({v: symbols[free_syms[k]]})
            solution.append(simplify(s))
    else:
        for s in sol:
            solution.append(simplify(s))
    solution = FiniteSet(tuple(solution))
    return solution
Solve system of N linear equations with M variables, which
means both under - and overdetermined systems are supported.
The possible number of solutions is zero, one or infinite.
Zero solutions throws a ValueError, where as infinite
solutions are represented parametrically in terms of given
symbols. For unique solution a FiniteSet of ordered tuple
is returned.

All Standard input formats are supported:
For the given set of Equations, the respective input types
are given below:

.. math:: 3x + 2y -   z = 1
.. math:: 2x - 2y + 4z = -2
.. math:: 2x -   y + 2z = 0

* Augmented Matrix Form, `system` given below:

::

          [3   2  -1  1]
 system = [2  -2   4 -2]
          [2  -1   2  0]

* List Of Equations Form

`system  =  [3x + 2y - z - 1, 2x - 2y + 4z + 2, 2x - y + 2z]`

* Input A & b Matrix Form (from Ax = b) are given as below:

::

     [3   2  -1 ]         [  1 ]
 A = [2  -2   4 ]    b =  [ -2 ]
     [2  -1   2 ]         [  0 ]

`system = (A, b)`

Symbols to solve for should be given as input in all the
cases either in an iterable or as comma separated arguments.
This is done to maintain consistency in returning solutions
in the form of variable input by the user.

The algorithm used here is Gauss-Jordan elimination, which
results, after elimination, in an row echelon form matrix.

Returns
=======

A FiniteSet of ordered tuple of values of `symbols` for which
the `system` has solution.

Please note that general FiniteSet is unordered, the solution
returned here is not simply a FiniteSet of solutions, rather
it is a FiniteSet of ordered tuple, i.e. the first & only
argument to FiniteSet is a tuple of solutions, which is ordered,
& hence the returned solution is ordered.

Also note that solution could also have been returned as an
ordered tuple, FiniteSet is just a wrapper `{}` around
the tuple. It has no other significance except for
the fact it is just used to maintain a consistent output
format throughout the solveset.

Returns EmptySet(), if the linear system is inconsistent.

Raises
======

ValueError
    The input is not valid.
    The symbols are not given.

Examples
========

>>> from sympy import Matrix, S, linsolve, symbols
>>> x, y, z = symbols("x, y, z")
>>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])
>>> b = Matrix([3, 6, 9])
>>> A
Matrix([
[1, 2,  3],
[4, 5,  6],
[7, 8, 10]])
>>> b
Matrix([
[3],
[6],
[9]])
>>> linsolve((A, b), [x, y, z])
{(-1, 2, 0)}

* Parametric Solution: In case the system is under determined, the function
  will return parametric solution in terms of the given symbols.
  Free symbols in the system are returned as it is. For e.g. in the system
  below, `z` is returned as the solution for variable z, which means z is a
  free symbol, i.e. it can take arbitrary values.

>>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> b = Matrix([3, 6, 9])
>>> linsolve((A, b), [x, y, z])
{(z - 1, -2*z + 2, z)}

* List of Equations as input

>>> Eqns = [3*x + 2*y - z - 1, 2*x - 2*y + 4*z + 2, - x + S(1)/2*y - z]
>>> linsolve(Eqns, x, y, z)
{(1, -2, -2)}

* Augmented Matrix as input

>>> aug = Matrix([[2, 1, 3, 1], [2, 6, 8, 3], [6, 8, 18, 5]])
>>> aug
Matrix([
[2, 1,  3, 1],
[2, 6,  8, 3],
[6, 8, 18, 5]])
>>> linsolve(aug, x, y, z)
{(3/10, 2/5, 0)}

* Solve for symbolic coefficients

>>> a, b, c, d, e, f = symbols('a, b, c, d, e, f')
>>> eqns = [a*x + b*y - c, d*x + e*y - f]
>>> linsolve(eqns, x, y)
{((-b*f + c*e)/(a*e - b*d), (a*f - c*d)/(a*e - b*d))}

* A degenerate system returns solution as set of given
  symbols.

>>> system = Matrix(([0,0,0], [0,0,0], [0,0,0]))
>>> linsolve(system, x, y)
{(x, y)}

* For an empty system linsolve returns empty set

>>> linsolve([ ], x)
EmptySet()
def linsolve(system, *symbols):
    '\n    Solve system of N linear equations with M variables, which\n    means both under - and overdetermined systems are supported.\n    The possible number of solutions is zero, one or infinite.\n    Zero solutions throws a ValueError, where as infinite\n    solutions are represented parametrically in terms of given\n    symbols. For unique solution a FiniteSet of ordered tuple\n    is returned.\n\n    All Standard input formats are supported:\n    For the given set of Equations, the respective input types\n    are given below:\n\n    .. math:: 3x + 2y -   z = 1\n    .. math:: 2x - 2y + 4z = -2\n    .. math:: 2x -   y + 2z = 0\n\n    * Augmented Matrix Form, `system` given below:\n\n    ::\n\n              [3   2  -1  1]\n     system = [2  -2   4 -2]\n              [2  -1   2  0]\n\n    * List Of Equations Form\n\n    `system  =  [3x + 2y - z - 1, 2x - 2y + 4z + 2, 2x - y + 2z]`\n\n    * Input A & b Matrix Form (from Ax = b) are given as below:\n\n    ::\n\n         [3   2  -1 ]         [  1 ]\n     A = [2  -2   4 ]    b =  [ -2 ]\n         [2  -1   2 ]         [  0 ]\n\n    `system = (A, b)`\n\n    Symbols to solve for should be given as input in all the\n    cases either in an iterable or as comma separated arguments.\n    This is done to maintain consistency in returning solutions\n    in the form of variable input by the user.\n\n    The algorithm used here is Gauss-Jordan elimination, which\n    results, after elimination, in an row echelon form matrix.\n\n    Returns\n    =======\n\n    A FiniteSet of ordered tuple of values of `symbols` for which\n    the `system` has solution.\n\n    Please note that general FiniteSet is unordered, the solution\n    returned here is not simply a FiniteSet of solutions, rather\n    it is a FiniteSet of ordered tuple, i.e. the first & only\n    argument to FiniteSet is a tuple of solutions, which is ordered,\n    & hence the returned solution is ordered.\n\n    Also note that solution could also have been returned as an\n    ordered tuple, FiniteSet is just a wrapper `{}` around\n    the tuple. It has no other significance except for\n    the fact it is just used to maintain a consistent output\n    format throughout the solveset.\n\n    Returns EmptySet(), if the linear system is inconsistent.\n\n    Raises\n    ======\n\n    ValueError\n        The input is not valid.\n        The symbols are not given.\n\n    Examples\n    ========\n\n    >>> from sympy import Matrix, S, linsolve, symbols\n    >>> x, y, z = symbols("x, y, z")\n    >>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 10]])\n    >>> b = Matrix([3, 6, 9])\n    >>> A\n    Matrix([\n    [1, 2,  3],\n    [4, 5,  6],\n    [7, 8, 10]])\n    >>> b\n    Matrix([\n    [3],\n    [6],\n    [9]])\n    >>> linsolve((A, b), [x, y, z])\n    {(-1, 2, 0)}\n\n    * Parametric Solution: In case the system is under determined, the function\n      will return parametric solution in terms of the given symbols.\n      Free symbols in the system are returned as it is. For e.g. in the system\n      below, `z` is returned as the solution for variable z, which means z is a\n      free symbol, i.e. it can take arbitrary values.\n\n    >>> A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n    >>> b = Matrix([3, 6, 9])\n    >>> linsolve((A, b), [x, y, z])\n    {(z - 1, -2*z + 2, z)}\n\n    * List of Equations as input\n\n    >>> Eqns = [3*x + 2*y - z - 1, 2*x - 2*y + 4*z + 2, - x + S(1)/2*y - z]\n    >>> linsolve(Eqns, x, y, z)\n    {(1, -2, -2)}\n\n    * Augmented Matrix as input\n\n    >>> aug = Matrix([[2, 1, 3, 1], [2, 6, 8, 3], [6, 8, 18, 5]])\n    >>> aug\n    Matrix([\n    [2, 1,  3, 1],\n    [2, 6,  8, 3],\n    [6, 8, 18, 5]])\n    >>> linsolve(aug, x, y, z)\n    {(3/10, 2/5, 0)}\n\n    * Solve for symbolic coefficients\n\n    >>> a, b, c, d, e, f = symbols(\'a, b, c, d, e, f\')\n    >>> eqns = [a*x + b*y - c, d*x + e*y - f]\n    >>> linsolve(eqns, x, y)\n    {((-b*f + c*e)/(a*e - b*d), (a*f - c*d)/(a*e - b*d))}\n\n    * A degenerate system returns solution as set of given\n      symbols.\n\n    >>> system = Matrix(([0,0,0], [0,0,0], [0,0,0]))\n    >>> linsolve(system, x, y)\n    {(x, y)}\n\n    * For an empty system linsolve returns empty set\n\n    >>> linsolve([ ], x)\n    EmptySet()\n\n    '
    if (not system):
        return S.EmptySet
    if (not symbols):
        raise ValueError('Symbols must be given, for which solution of the system is to be found.')
    if hasattr(symbols[0], '__iter__'):
        symbols = symbols[0]
    try:
        sym = symbols[0].is_Symbol
    except AttributeError:
        sym = False
    if (not sym):
        raise ValueError(('Symbols or iterable of symbols must be given as second argument, not type %s: %s' % (type(symbols[0]), symbols[0])))
    if isinstance(system, Matrix):
        (A, b) = (system[:, :(- 1)], system[:, (- 1):])
    elif hasattr(system, '__iter__'):
        if ((len(system) == 2) and system[0].is_Matrix):
            (A, b) = (system[0], system[1])
        if (not system[0].is_Matrix):
            (A, b) = linear_eq_to_matrix(system, symbols)
    else:
        raise ValueError('Invalid arguments')
    try:
        (sol, params, free_syms) = A.gauss_jordan_solve(b, freevar=True)
    except ValueError:
        return EmptySet()
    solution = []
    if params:
        for s in sol:
            for (k, v) in enumerate(params):
                s = s.xreplace({v: symbols[free_syms[k]]})
            solution.append(simplify(s))
    else:
        for s in sol:
            solution.append(simplify(s))
    solution = FiniteSet(tuple(solution))
    return solution