(A, B)
return simplified(x_0*x_1 + A*z_0*z_1, z_0*x_1 + x_0*z_1, t_1*t_2*y_1)
Lagrange's `descent()` with lattice-reduction to find solutions to
    `x^2 = Ay^2 + Bz^2`.

    Here `A` and `B` should be square free and pairwise prime. Always should be
    called with suitable ``A`` and ``B`` so that the above equation has
    solutions.

    This is more faster than the normal Lagrange's descent algorithm because
    the gaussian reduction is used.

    Examples
    ========

    >>> from sympy.solvers.diophantine import descent
    >>> descent(3, 1) # x**2 = 3*y**2 + z**2
    (1, 0, 1)

    `(x, y, z) = (1, 0, 1)` is a solution to the above equation.

    >>> descent(41, -113)
    (-16, -3, 1)

    References
    ==========

    .. [1] Efficient Solution of Rational Conices, J. E. Cremona and D. Rusin,
           Mathematics of Computation, Volume 00, Number 0.
Lagrange's `descent()` with lattice-reduction to find solutions to
    `x^2 = Ay^2 + Bz^2`.
Lagrange s descent () with lattice - reduction to find solutions to x^2 = Ay^2 + Bz^2 .
def descent(A, B):
    """
    Lagrange's `descent()` with lattice-reduction to find solutions to
    `x^2 = Ay^2 + Bz^2`.

    Here `A` and `B` should be square free and pairwise prime. Always should be
    called with suitable ``A`` and ``B`` so that the above equation has
    solutions.

    This is more faster than the normal Lagrange's descent algorithm because
    the gaussian reduction is used.

    Examples
    ========

    >>> from sympy.solvers.diophantine import descent
    >>> descent(3, 1) # x**2 = 3*y**2 + z**2
    (1, 0, 1)

    `(x, y, z) = (1, 0, 1)` is a solution to the above equation.

    >>> descent(41, -113)
    (-16, -3, 1)

    References
    ==========

    .. [1] Efficient Solution of Rational Conices, J. E. Cremona and D. Rusin,
           Mathematics of Computation, Volume 00, Number 0.
    """
    if abs(A) > abs(B):
        x, y, z = descent(B, A)
        return x, z, y

    if B == 1:
        return (1, 0, 1)
    if A == 1:
        return (1, 1, 0)
    if B == -1:
        return (None, None, None)
    if B == -A:
        return (0, 1, 1)
    if B == A:
        x, z, y = descent(-1, A)
        return (A*y, z, x)

    w = sqrt_mod(A, B)
    x_0, z_0 = gaussian_reduce(w, A, B)

    t = (x_0**2 - A*z_0**2) // B
    t_2 = square_factor(t)
    t_1 = t // t_2**2

    x_1, z_1, y_1 = descent(A, t_1)

    return simplified(x_0*x_1 + A*z_0*z_1, z_0*x_1 + x_0*z_1, t_1*t_2*y_1)
def descent ( A , B ) : if abs ( A ) > abs ( B ) : x , y , z = descent ( B , A ) return x , z , y if B == 1 : return ( 1 , 0 , 1 ) if A == 1 : return ( 1 , 1 , 0 ) if B == - 1 : return ( None , None , None ) if B == - A : return ( 0 , 1 , 1 ) if B == A : x , z , y = descent ( - 1 , A ) return ( A * y , z , x ) w = sqrt_mod ( A , B ) x_0 , z_0 = gaussian_reduce ( w , A , B ) t = ( x_0 ** 2 - A * z_0 ** 2 ) // B t_2 = square_factor ( t ) t_1 = t // t_2 ** 2 x_1 , z_1 , y_1 = descent ( A , t_1 ) return simplified ( x_0 * x_1 + A * z_0 * z_1 , z_0 * x_1 + x_0 * z_1 , t_1 * t_2 * y_1 )