/*=============================================================================

    This file is part of FLINT.

    FLINT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    FLINT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with FLINT; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

=============================================================================*/
/******************************************************************************

    Copyright (C) 2010 William Hart
    Copyright (C) 2010 Andy Novocin
    Copyright (C) 2014 Abhinav Baid

******************************************************************************/

*******************************************************************************

    Memory management

*******************************************************************************

mpf * _mpf_vec_init(slong len)

    Returns a vector of the given length of initialised \code{mpf}'s
    with at least the given precision.
 
void _mpf_vec_clear(mpf * vec, slong len)

    Clears the given vector.

*******************************************************************************

    Randomisation

*******************************************************************************

void _mpf_vec_randtest(mpf * f, flint_rand_t state, 
                        slong len, mp_bitcnt_t bits)

    Sets the entries of a vector of the given length to random numbers in the 
    interval $[0, 1)$ with \code{bits} significant bits in the mantissa or less if
    their precision is smaller.

*******************************************************************************

    Assignment and basic manipulation

*******************************************************************************

void _mpf_vec_zero(mpf * vec, slong len)

    Zeros the vector \code{(vec, len)}.

void _mpf_vec_set(mpf * vec1, const mpf * vec2, slong len2)

    Copies the vector \code{vec2} of the given length into \code{vec1}. 
    A check is made to ensure \code{vec1} and \code{vec2} are different.
    
*******************************************************************************

    Comparison

*******************************************************************************

int _mpf_vec_equal(const mpf * vec1, const mpf * vec2, slong len)

    Compares two vectors of the given length and returns $1$ if they are 
    equal, otherwise returns $0$.

int _mpf_vec_is_zero(const mpf * vec, slong len)

    Returns $1$ if \code{(vec, len)} is zero, and $0$ otherwise.
    
int _mpf_vec_approx_equal(const mpf * vec1, const mpf * vec2, slong len, 
                            mp_bitcnt_t bits)

    Compares two vectors of the given length and returns $1$ if the first
    \code{bits} bits of their entries are equal, otherwise returns $0$.
    
*******************************************************************************

    Addition and subtraction

*******************************************************************************

void _mpf_vec_add(mpf * res, const mpf * vec1, const mpf * vec2, slong len2)

    Adds the given vectors of the given length together and stores the 
    result in \code{res}.
    
void _mpf_vec_sub(mpf * res, const mpf * vec1, 
                    const mpf * vec2, slong len2)

    Sets \code{(res, len2)} to \code{(vec1, len2)} minus \code{(vec2, len2)}.

*******************************************************************************

    Scalar multiplication

*******************************************************************************

void _mpf_vec_scalar_mul_mpf(mpf * res, const mpf * vec, 
                              slong len, mpf_t c)

    Multiplies the vector with given length by the scalar $c$ and 
    sets \code{res} to the result.

void _mpf_vec_scalar_mul_2exp(mpf * res, 
                               const mpf * vec, slong len, mp_bitcnt_t exp)

    Multiplies the given vector of the given length by \code{2^exp}.

*******************************************************************************

    Dot product and norm

*******************************************************************************

void _mpf_vec_dot(mpf_t res, const mpf * vec1, 
                   const mpf * vec2, slong len2)

    Sets \code{res} to the dot product of \code{(vec1, len2)} with 
    \code{(vec2, len2)}.
    
void _mpf_vec_norm(mpf_t res, mpf * vec, slong len)

    Sets \code{res} to the sqaure of the Euclidean norm of 
    \code{(vec, len)}.

int _mpf_vec_dot2(mpf_t res, const mpf * vec1,
                   const mpf * vec2, slong len2, mp_bitcnt_t prec)

    Sets \code{res} to the dot product of \code{(vec1, len2)} with
    \code{(vec2, len2)}. The temporary variable used has its precision
    set to be at least \code{prec} bits. Returns 0 if a probable
    cancellation is detected, and otherwise returns a non-zero value.

void _mpf_vec_norm2(mpf_t res, mpf * vec, slong len, mp_bitcnt_t prec)

    Sets \code{res} to the sqaure of the Euclidean norm of 
    \code{(vec, len)}. The temporary variable used has its precision
    set to be at least \code{prec} bits.
