text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sqrt(x, context=None): """ Return the square root of ``x``. Return -0 if x is -0, to be consistent with the IEEE 754 standard. Return NaN if x is negative. "...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_sqrt, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def rec_sqrt(x, context=None): """ Return the reciprocal square root of x. Return +Inf if x is ±0, +0 if x is +Inf, and NaN if x is negative. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_rec_sqrt, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cbrt(x, context=None): """ Return the cube root of x. For x negative, return a negative number. The cube root of -0 is defined to be -0. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_cbrt, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def root(x, k, context=None): """ Return the kth root of x. For k odd and x negative (including -Inf), return a negative number. For k even and x negative (inclu...
if k < 0: raise ValueError("root function not implemented for negative k") return _apply_function_in_current_context( BigFloat, mpfr.mpfr_root, (BigFloat._implicit_convert(x), k), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def pow(x, y, context=None): """ Return ``x`` raised to the power ``y``. Special values are handled as described in the ISO C99 and IEEE 754-2008 standards for t...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_pow, ( BigFloat._implicit_convert(x), BigFloat._implicit_convert(y), ), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def neg(x, context=None): """ Return -x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_neg, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cmp(op1, op2): """ Perform a three-way comparison of op1 and op2. Return a positive value if op1 > op2, zero if op1 = op2, and a negative value if op1 < op2....
op1 = BigFloat._implicit_convert(op1) op2 = BigFloat._implicit_convert(op2) if is_nan(op1) or is_nan(op2): raise ValueError("Cannot perform comparison with NaN.") return mpfr.mpfr_cmp(op1, op2)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cmpabs(op1, op2): """ Compare the absolute values of op1 and op2. Return a positive value if op1 > op2, zero if op1 = op2, and a negative value if op1 < op2....
op1 = BigFloat._implicit_convert(op1) op2 = BigFloat._implicit_convert(op2) if is_nan(op1) or is_nan(op2): raise ValueError("Cannot perform comparison with NaN.") return mpfr.mpfr_cmpabs(op1, op2)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sgn(x): """ Return the sign of x. Return a positive integer if x > 0, 0 if x == 0, and a negative integer if x < 0. Raise ValueError if x is a NaN. This func...
x = BigFloat._implicit_convert(x) if is_nan(x): raise ValueError("Cannot take sign of a NaN.") return mpfr.mpfr_sgn(x)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def greater(x, y): """ Return True if x > y and False otherwise. This function returns False whenever x and/or y is a NaN. """
x = BigFloat._implicit_convert(x) y = BigFloat._implicit_convert(y) return mpfr.mpfr_greater_p(x, y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def greaterequal(x, y): """ Return True if x >= y and False otherwise. This function returns False whenever x and/or y is a NaN. """
x = BigFloat._implicit_convert(x) y = BigFloat._implicit_convert(y) return mpfr.mpfr_greaterequal_p(x, y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def less(x, y): """ Return True if x < y and False otherwise. This function returns False whenever x and/or y is a NaN. """
x = BigFloat._implicit_convert(x) y = BigFloat._implicit_convert(y) return mpfr.mpfr_less_p(x, y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def lessequal(x, y): """ Return True if x <= y and False otherwise. This function returns False whenever x and/or y is a NaN. """
x = BigFloat._implicit_convert(x) y = BigFloat._implicit_convert(y) return mpfr.mpfr_lessequal_p(x, y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def equal(x, y): """ Return True if x == y and False otherwise. This function returns False whenever x and/or y is a NaN. """
x = BigFloat._implicit_convert(x) y = BigFloat._implicit_convert(y) return mpfr.mpfr_equal_p(x, y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def notequal(x, y): """ Return True if x != y and False otherwise. This function returns True whenever x and/or y is a NaN. """
x = BigFloat._implicit_convert(x) y = BigFloat._implicit_convert(y) return not mpfr.mpfr_equal_p(x, y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def unordered(x, y): """ Return True if x or y is a NaN and False otherwise. """
x = BigFloat._implicit_convert(x) y = BigFloat._implicit_convert(y) return mpfr.mpfr_unordered_p(x, y)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def log(x, context=None): """ Return the natural logarithm of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_log, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def log2(x, context=None): """ Return the base-two logarithm of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_log2, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def log10(x, context=None): """ Return the base-ten logarithm of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_log10, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def exp(x, context=None): """ Return the exponential of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_exp, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def exp2(x, context=None): """ Return two raised to the power x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_exp2, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def exp10(x, context=None): """ Return ten raised to the power x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_exp10, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cos(x, context=None): """ Return the cosine of ``x``. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_cos, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sin(x, context=None): """ Return the sine of ``x``. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_sin, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tan(x, context=None): """ Return the tangent of ``x``. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_tan, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sec(x, context=None): """ Return the secant of ``x``. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_sec, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def csc(x, context=None): """ Return the cosecant of ``x``. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_csc, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cot(x, context=None): """ Return the cotangent of ``x``. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_cot, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def acos(x, context=None): """ Return the inverse cosine of ``x``. The mathematically exact result lies in the range [0, π]. However, note that as a result of ro...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_acos, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def asin(x, context=None): """ Return the inverse sine of ``x``. The mathematically exact result lies in the range [-π/2, π/2]. However, note that as a result of...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_asin, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def atan(x, context=None): """ Return the inverse tangent of ``x``. The mathematically exact result lies in the range [-π/2, π/2]. However, note that as a result...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_atan, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cosh(x, context=None): """ Return the hyperbolic cosine of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_cosh, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sinh(x, context=None): """ Return the hyperbolic sine of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_sinh, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tanh(x, context=None): """ Return the hyperbolic tangent of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_tanh, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sech(x, context=None): """ Return the hyperbolic secant of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_sech, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def csch(x, context=None): """ Return the hyperbolic cosecant of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_csch, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def coth(x, context=None): """ Return the hyperbolic cotangent of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_coth, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def acosh(x, context=None): """ Return the inverse hyperbolic cosine of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_acosh, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def asinh(x, context=None): """ Return the inverse hyperbolic sine of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_asinh, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def atanh(x, context=None): """ Return the inverse hyperbolic tangent of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_atanh, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def log1p(x, context=None): """ Return the logarithm of one plus x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_log1p, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def expm1(x, context=None): """ Return one less than the exponential of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_expm1, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def eint(x, context=None): """ Return the exponential integral of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_eint, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def li2(x, context=None): """ Return the real part of the dilogarithm of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_li2, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def gamma(x, context=None): """ Return the value of the Gamma function of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_gamma, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def lngamma(x, context=None): """ Return the value of the logarithm of the Gamma function of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_lngamma, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def lgamma(x, context=None): """ Return the logarithm of the absolute value of the Gamma function at x. """
return _apply_function_in_current_context( BigFloat, lambda rop, op, rnd: mpfr.mpfr_lgamma(rop, op, rnd)[0], (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def zeta(x, context=None): """ Return the value of the Riemann zeta function on x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_zeta, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def erf(x, context=None): """ Return the value of the error function at x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_erf, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def erfc(x, context=None): """ Return the value of the complementary error function at x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_erfc, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def j0(x, context=None): """ Return the value of the first kind Bessel function of order 0 at x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_j0, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def j1(x, context=None): """ Return the value of the first kind Bessel function of order 1 at x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_j1, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def jn(n, x, context=None): """ Return the value of the first kind Bessel function of order ``n`` at ``x``. ``n`` should be a Python integer. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_jn, (n, BigFloat._implicit_convert(x)), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def y0(x, context=None): """ Return the value of the second kind Bessel function of order 0 at x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_y0, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def y1(x, context=None): """ Return the value of the second kind Bessel function of order 1 at x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_y1, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def yn(n, x, context=None): """ Return the value of the second kind Bessel function of order ``n`` at ``x``. ``n`` should be a Python integer. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_yn, (n, BigFloat._implicit_convert(x)), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def agm(x, y, context=None): """ Return the arithmetic geometric mean of x and y. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_agm, ( BigFloat._implicit_convert(x), BigFloat._implicit_convert(y), ), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def hypot(x, y, context=None): """ Return the Euclidean norm of x and y, i.e., the square root of the sum of the squares of x and y. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_hypot, ( BigFloat._implicit_convert(x), BigFloat._implicit_convert(y), ), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ai(x, context=None): """ Return the Airy function of x. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_ai, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ceil(x, context=None): """ Return the next higher or equal integer to x. If the result is not exactly representable, it will be rounded according to the curr...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_rint_ceil, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def floor(x, context=None): """ Return the next lower or equal integer to x. If the result is not exactly representable, it will be rounded according to the curr...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_rint_floor, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def trunc(x, context=None): """ Return the next integer towards zero. If the result is not exactly representable, it will be rounded according to the current con...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_rint_trunc, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def frac(x, context=None): """ Return the fractional part of ``x``. The result has the same sign as ``x``. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_frac, (BigFloat._implicit_convert(x),), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def min(x, y, context=None): """ Return the minimum of x and y. If x and y are both NaN, return NaN. If exactly one of x and y is NaN, return the non-NaN value. ...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_min, ( BigFloat._implicit_convert(x), BigFloat._implicit_convert(y), ), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def max(x, y, context=None): """ Return the maximum of x and y. If x and y are both NaN, return NaN. If exactly one of x and y is NaN, return the non-NaN value. ...
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_max, ( BigFloat._implicit_convert(x), BigFloat._implicit_convert(y), ), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def copysign(x, y, context=None): """ Return a new BigFloat object with the magnitude of x but the sign of y. """
return _apply_function_in_current_context( BigFloat, mpfr.mpfr_copysign, ( BigFloat._implicit_convert(x), BigFloat._implicit_convert(y), ), context, )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def exact(cls, value, precision=None): """Convert an integer, float or BigFloat with no loss of precision. Also convert a string with given precision. This const...
# figure out precision to use if isinstance(value, six.string_types): if precision is None: raise TypeError("precision must be supplied when " "converting from a string") else: if precision is not None: rais...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _significand(self): """Return the significand of self, as a BigFloat. If self is a nonzero finite number, return a BigFloat m with the same precision as self...
m = self.copy() if self and is_finite(self): mpfr.mpfr_set_exp(m, 0) mpfr.mpfr_setsign(m, m, False, ROUND_TIES_TO_EVEN) return m
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _exponent(self): """Return the exponent of self, as an integer. The exponent is defined as the unique integer k such that 2**(k-1) <= abs(self) < 2**k. If se...
if self and is_finite(self): return mpfr.mpfr_get_exp(self) if not self: return '0' elif is_inf(self): return 'inf' elif is_nan(self): return 'nan' else: assert False, "shouldn't ever get here"
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def copy_neg(self): """ Return a copy of self with the opposite sign bit. Unlike -self, this does not make use of the context: the result has the same precision ...
result = mpfr.Mpfr_t.__new__(BigFloat) mpfr.mpfr_init2(result, self.precision) new_sign = not self._sign() mpfr.mpfr_setsign(result, self, new_sign, ROUND_TIES_TO_EVEN) return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def copy_abs(self): """ Return a copy of self with the sign bit unset. Unlike abs(self), this does not make use of the context: the result has the same precision...
result = mpfr.Mpfr_t.__new__(BigFloat) mpfr.mpfr_init2(result, self.precision) mpfr.mpfr_setsign(result, self, False, ROUND_TIES_TO_EVEN) return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def hex(self): """Return a hexadecimal representation of a BigFloat."""
sign = '-' if self._sign() else '' e = self._exponent() if isinstance(e, six.string_types): return sign + e m = self._significand() _, digits, _ = _mpfr_get_str2( 16, 0, m, ROUND_TIES_TO_EVEN, ) # only...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _format_to_floating_precision(self, precision): """ Format a nonzero finite BigFloat instance to a given number of significant digits. Returns a triple (nega...
if precision <= 0: raise ValueError("precision argument should be at least 1") sign, digits, exp = _mpfr_get_str2( 10, precision, self, ROUND_TIES_TO_EVEN, ) return sign, digits, exp - len(digits)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _format_to_fixed_precision(self, precision): """ Format 'self' to a given number of digits after the decimal point. Returns a triple (negative, digits, exp) ...
# MPFR only provides functions to format to a given number of # significant digits. So we must: # # (1) Identify an e such that 10**(e-1) <= abs(x) < 10**e. # # (2) Determine the number of significant digits required, and format # to that number of sig...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _implicit_convert(cls, arg): """Implicit conversion used for binary operations, comparisons, functions, etc. Return value should be an instance of BigFloat."...
# ints, long and floats mix freely with BigFloats, and are # converted exactly. if isinstance(arg, six.integer_types) or isinstance(arg, float): return cls.exact(arg) elif isinstance(arg, BigFloat): return arg else: raise TypeError("Unable to...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def calculate_merkle_pairs(bin_hashes, hash_function=bin_double_sha256): """ Calculate the parents of a row of a merkle tree. Takes in a list of binary hashes, r...
hashes = list(bin_hashes) # if there are an odd number of hashes, double up the last one if len(hashes) % 2 == 1: hashes.append(hashes[-1]) new_hashes = [] for i in range(0, len(hashes), 2): new_hashes.append(hash_function(hashes[i] + hashes[i+1])) return new_hashes
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def verify_merkle_path(merkle_root_hex, serialized_path, leaf_hash_hex, hash_function=bin_double_sha256): """ Verify a merkle path. The given path is the path fr...
merkle_root = hex_to_bin_reversed(merkle_root_hex) leaf_hash = hex_to_bin_reversed(leaf_hash_hex) path = MerkleTree.path_deserialize(serialized_path) path = [{'order': p['order'], 'hash': hex_to_bin_reversed(p['hash'])} for p in path] if len(path) == 0: raise ValueError("Empty path")...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _coords2idx(self, coords): """ Converts from sky coordinates to pixel indices. Args: coords (:obj:`astropy.coordinates.SkyCoord`): Sky coordinates. Returns:...
x = self._coords2vec(coords) idx = self._kd.query(x, p=self._metric_p, distance_upper_bound=self._max_pix_scale) return idx[1]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _gal2idx(self, gal): """ Converts from Galactic coordinates to pixel indices. Args: gal (:obj:`astropy.coordinates.SkyCoord`): Galactic coordinates. Must st...
# Make sure that l is in domain [-180 deg, 180 deg) l = coordinates.Longitude(gal.l, wrap_angle=180.*units.deg) j = (self._inv_pix_scale * (l.deg - self._l_bounds[0])).astype('i4') k = (self._inv_pix_scale * (gal.b.deg - self._b_bounds[0])).astype('i4') idx = (j < 0) | (j >= ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_block_hash( self, block_hash ): """ Append up to 2000 block hashes for which to get headers. """
if len(self.block_hashes) > 2000: raise Exception("A getheaders request cannot have over 2000 block hashes") hash_num = int("0x" + block_hash, 16) bh = BlockHash() bh.block_hash = hash_num self.block_hashes.append( bh ) self.hash_stop = hash_num
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run( self ): """ Interact with the blockchain peer, until we get a socket error or we exit the loop explicitly. Return True on success Raise on error """
self.handshake() try: self.loop() except socket.error, se: if self.finished: return True else: raise
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def handle_ping(self, message_header, message): """ This method will handle the Ping message and then will answer every Ping message with a Pong message using th...
log.debug("handle ping") pong = Pong() pong.nonce = message.nonce log.debug("send pong") self.send_message(pong)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def init(cls, path): """ Set up an SPV client. If the locally-stored headers do not exist, then create a stub headers file with the genesis block information. ""...
if not os.path.exists( path ): block_header_serializer = BlockHeaderSerializer() genesis_block_header = BlockHeader() if USE_MAINNET: # we know the mainnet block header # but we don't know the testnet/regtest block header gen...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def height(cls, path): """ Get the locally-stored block height """
if os.path.exists( path ): sb = os.stat( path ) h = (sb.st_size / BLOCK_HEADER_SIZE) - 1 return h else: return None
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def read_header(cls, headers_path, block_height, allow_none=False): """ Get a block header at a particular height from disk. Return the header if found Return No...
if os.path.exists(headers_path): header_parser = BlockHeaderSerializer() sb = os.stat( headers_path ) if sb.st_size < BLOCK_HEADER_SIZE * block_height: # beyond EOF if allow_none: return None else: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def block_header_verify( cls, headers_path, block_id, block_hash, block_header ): """ Given the block's numeric ID, its hash, and the bitcoind-returned block_dat...
prev_header = cls.read_header( headers_path, block_id - 1 ) prev_hash = prev_header['hash'] return bits.block_header_verify( block_header, prev_hash, block_hash )
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tx_hash( cls, tx ): """ Calculate the hash of a transction structure given by bitcoind """
tx_hex = bits.btc_bitcoind_tx_serialize( tx ) tx_hash = hashing.bin_double_sha256(tx_hex.decode('hex'))[::-1].encode('hex') return tx_hash
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tx_verify( cls, verified_block_txids, tx ): """ Given the block's verified block txids, verify that a transaction is legit. @tx must be a dict with the follo...
tx_hash = cls.tx_hash( tx ) return tx_hash in verified_block_txids
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def verify_header_chain(cls, path, chain=None): """ Verify that a given chain of block headers has sufficient proof of work. """
if chain is None: chain = SPVClient.load_header_chain( path ) prev_header = chain[0] for i in xrange(1, len(chain)): header = chain[i] height = header.get('block_height') prev_hash = prev_header.get('hash') if prev_hash != he...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sync_header_chain(cls, path, bitcoind_server, last_block_id ): """ Synchronize our local block headers up to the last block ID given. @last_block_id is *incl...
current_block_id = SPVClient.height( path ) if current_block_id is None: assert USE_TESTNET current_block_id = -1 assert (current_block_id >= 0 and USE_MAINNET) or USE_TESTNET if current_block_id < last_block_id: if USE_MAINNET: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def IEEEContext(bitwidth): """ Return IEEE 754-2008 context for a given bit width. The IEEE 754 standard specifies binary interchange formats with bitwidths 16, ...
try: precision = {16: 11, 32: 24, 64: 53, 128: 113}[bitwidth] except KeyError: if not (bitwidth >= 128 and bitwidth % 32 == 0): raise ValueError("nonstandard bitwidth: bitwidth should be " "16, 32, 64, 128, or k*32 for some k >= 4") # The formula...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def view(molecule, viewer=settings['defaults']['viewer'], use_curr_dir=False): """View your molecule or list of molecules. .. note:: This function writes a tempo...
try: molecule.view(viewer=viewer, use_curr_dir=use_curr_dir) except AttributeError: if pd.api.types.is_list_like(molecule): cartesian_list = molecule else: raise ValueError('Argument is neither list nor Cartesian.') if use_curr_dir: TEMP_DIR =...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def to_molden(cartesian_list, buf=None, sort_index=True, overwrite=True, float_format='{:.6f}'.format): """Write a list of Cartesians into a molden file. .. note...
if sort_index: cartesian_list = [molecule.sort_index() for molecule in cartesian_list] give_header = ("[MOLDEN FORMAT]\n" + "[N_GEO]\n" + str(len(cartesian_list)) + "\n" + '[GEOCONV]\n' + 'energy\n{energy}' ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def read_molden(inputfile, start_index=0, get_bonds=True): """Read a molden file. Args: inputfile (str): start_index (int): Returns: list: A list containing :c...
from chemcoord.cartesian_coordinates.cartesian_class_main import Cartesian with open(inputfile, 'r') as f: found = False while not found: line = f.readline() if '[N_GEO]' in line: found = True number_of_molecules = int(f.readline().strip()...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def concat(cartesians, ignore_index=False, keys=None): """Join list of cartesians into one molecule. Wrapper around the :func:`pandas.concat` function. Default v...
frames = [molecule._frame for molecule in cartesians] new = pd.concat(frames, ignore_index=ignore_index, keys=keys, verify_integrity=True) if type(ignore_index) is bool: new = pd.concat(frames, ignore_index=ignore_index, keys=keys, verify_integrity=True)...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def dot(A, B): """Matrix multiplication between A and B This function is equivalent to ``A @ B``, which is unfortunately not possible under python 2.x. Args: A (...
try: result = A.__matmul__(B) if result is NotImplemented: result = B.__rmatmul__(A) except AttributeError: result = B.__rmatmul__(A) return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def orthonormalize_righthanded(basis): """Orthonormalizes righthandedly a given 3D basis. This functions returns a right handed orthonormalize_righthandedd basis...
v1, v2 = basis[:, 0], basis[:, 1] e1 = normalize(v1) e3 = normalize(np.cross(e1, v2)) e2 = normalize(np.cross(e3, e1)) return np.array([e1, e2, e3]).T
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_kabsch_rotation(Q, P): """Calculate the optimal rotation from ``P`` unto ``Q``. Using the Kabsch algorithm the optimal rotation matrix for the rotation o...
# Naming of variables follows the wikipedia article: # http://en.wikipedia.org/wiki/Kabsch_algorithm A = np.dot(np.transpose(P), Q) # One can't initialize an array over its transposed V, S, W = np.linalg.svd(A) # pylint:disable=unused-variable W = W.T d = np.linalg.det(np.dot(W, V.T)) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def apply_grad_zmat_tensor(grad_C, construction_table, cart_dist): """Apply the gradient for transformation to Zmatrix space onto cart_dist. Args: grad_C (:class...
if (construction_table.index != cart_dist.index).any(): message = "construction_table and cart_dist must use the same index" raise ValueError(message) X_dist = cart_dist.loc[:, ['x', 'y', 'z']].values.T C_dist = np.tensordot(grad_C, X_dist, axes=([3, 2], [0, 1])).T if C_dist.dtype == np...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def _remove_child_node(node, context, xast, if_empty=False): '''Remove a child node based on the specified xpath. :param node: lxml element relative to which the xpath will be interpreted :param context: any context required for the xpath (e.g., namespace definitions) :param xast: parsed xpat...