本文整理汇总了Python中miscellaneous.sqrt函数的典型用法代码示例。如果您正苦于以下问题:Python sqrt函数的具体用法?Python sqrt怎么用?Python sqrt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqrt函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: eval
def eval(cls, arg):
if arg.is_Number:
if arg is S.NaN:
return S.NaN
elif arg is S.Zero:
return S.Zero
if arg.could_extract_minus_sign():
return -cls(-arg)
i_coeff = arg.as_coefficient(S.ImaginaryUnit)
if i_coeff is not None:
return S.ImaginaryUnit * C.tanh(i_coeff)
pi_coeff = arg.as_coefficient(S.Pi)
if pi_coeff is not None:
if pi_coeff.is_integer:
return S.Zero
elif pi_coeff.is_Rational:
cst_table = {
#2 : S.ComplexInfinity,
3 : sqrt(3),
4 : S.One,
6 : 1 / sqrt(3),
}
try:
result = cst_table[pi_coeff.q]
if (2*pi_coeff.p // pi_coeff.q) % 4 in (1, 3):
return -result
else:
return result
except KeyError:
pass
if arg.is_Add:
x, m = _peeloff_pi(arg)
if m:
if (m*2/S.Pi) % 2 == 0:
return tan(x)
else:
return -cot(x)
if arg.func is atan:
return arg.args[0]
if arg.func is asin:
x = arg.args[0]
return x / sqrt(1 - x**2)
if arg.func is acos:
x = arg.args[0]
return sqrt(1 - x**2) / x
if arg.func is acot:
x = arg.args[0]
return 1 / x
示例2: canonize
def canonize(cls, arg):
if arg.is_Number:
if arg is S.NaN:
return S.NaN
#elif arg is S.Zero:
# return S.ComplexInfinity
elif arg.is_negative:
return -cls(-arg)
else:
i_coeff = arg.as_coefficient(S.ImaginaryUnit)
if i_coeff is not None:
return -S.ImaginaryUnit * C.coth(i_coeff)
else:
pi_coeff = arg.as_coefficient(S.Pi)
if pi_coeff is not None:
#if pi_coeff.is_integer:
# return S.ComplexInfinity
if pi_coeff.is_Rational:
cst_table = {
2 : S.Zero,
3 : 1 / sqrt(3),
4 : S.One,
6 : sqrt(3)
}
try:
result = cst_table[pi_coeff.q]
if (2*pi_coeff.p // pi_coeff.q) % 4 in (1, 3):
return -result
else:
return result
except KeyError:
pass
coeff, terms = arg.as_coeff_terms()
if coeff.is_negative:
return -cls(-arg)
if isinstance(arg, acot):
return arg.args[0]
if isinstance(arg, atan):
x = arg.args[0]
return 1 / x
if isinstance(arg, asin):
x = arg.args[0]
return sqrt(1 - x**2) / x
if isinstance(arg, acos):
x = arg.args[0]
return x / sqrt(1 - x**2)
示例3: eval
def eval(cls, arg):
if arg.is_Number:
if arg is S.NaN:
return S.NaN
if arg.could_extract_minus_sign():
return -cls(-arg)
i_coeff = arg.as_coefficient(S.ImaginaryUnit)
if i_coeff is not None:
return -S.ImaginaryUnit * C.coth(i_coeff)
pi_coeff = arg.as_coefficient(S.Pi)
if pi_coeff is not None:
if pi_coeff.is_Rational:
cst_table = {
2 : S.Zero,
3 : 1 / sqrt(3),
4 : S.One,
6 : sqrt(3)
}
try:
result = cst_table[pi_coeff.q]
if (2*pi_coeff.p // pi_coeff.q) % 4 in (1, 3):
return -result
else:
return result
except KeyError:
pass
if arg.func is acot:
return arg.args[0]
if arg.func is atan:
x = arg.args[0]
return 1 / x
if arg.func is asin:
x = arg.args[0]
return sqrt(1 - x**2) / x
if arg.func is acos:
x = arg.args[0]
return x / sqrt(1 - x**2)
示例4: eval
def eval(cls, arg):
if arg.is_Number:
if arg is S.NaN:
return S.NaN
elif arg is S.Infinity:
return S.Infinity * S.ImaginaryUnit
elif arg is S.NegativeInfinity:
return S.NegativeInfinity * S.ImaginaryUnit
elif arg is S.Zero:
return S.Pi / 2
elif arg is S.One:
return S.Zero
elif arg is S.NegativeOne:
return S.Pi
if arg.is_number:
cst_table = {
S.Half : S.Pi/3,
-S.Half : 2*S.Pi/3,
sqrt(2)/2 : S.Pi/4,
-sqrt(2)/2 : 3*S.Pi/4,
1/sqrt(2) : S.Pi/4,
-1/sqrt(2) : 3*S.Pi/4,
sqrt(3)/2 : S.Pi/6,
-sqrt(3)/2 : 5*S.Pi/6,
}
if arg in cst_table:
return cst_table[arg]
示例5: fdiff
def fdiff(self, argindex=1):
if argindex == 1:
return 1/sqrt(1 - self.args[0]**2)
else:
raise ArgumentIndexError(self, argindex)
示例6: _eval_rewrite_as_atan
def _eval_rewrite_as_atan(self, x):
if x > -1 and x <= 1:
return 2 * atan(sqrt(1 - x**2)/(1 + x))
else:
raise ValueError("The argument must be bounded in the interval (-1,1]")
示例7: _eval_rewrite_as_log
def _eval_rewrite_as_log(self, x):
return S.Pi/2 + S.ImaginaryUnit * C.log(S.ImaginaryUnit * x + sqrt(1 - x**2))
示例8: eval
def eval(cls, arg):
if arg.is_Number:
if arg is S.NaN:
return S.NaN
elif arg is S.Zero:
return S.Zero
elif arg.is_negative:
return -cls(-arg)
else:
i_coeff = arg.as_coefficient(S.ImaginaryUnit)
if i_coeff is not None:
return S.ImaginaryUnit * C.sinh(i_coeff)
else:
pi_coeff = arg.as_coefficient(S.Pi)
if pi_coeff is not None:
if pi_coeff.is_integer:
return S.Zero
elif pi_coeff.is_Rational:
cst_table_some = {
2 : S.One,
3 : S.Half*sqrt(3),
4 : S.Half*sqrt(2),
6 : S.Half,
}
cst_table_more = {
(1, 5) : sqrt((5 - sqrt(5)) / 8),
(2, 5) : sqrt((5 + sqrt(5)) / 8)
}
p = pi_coeff.p
q = pi_coeff.q
Q, P = p // q, p % q
try:
result = cst_table_some[q]
except KeyError:
if abs(P) > q // 2:
P = q - P
try:
result = cst_table_more[(P, q)]
except KeyError:
if P != p:
result = cls(C.Rational(P, q)*S.Pi)
else:
return None
if Q % 2 == 1:
return -result
else:
return result
if arg.is_Mul and arg.args[0].is_negative:
return -cls(-arg)
if arg.is_Add:
x, m = arg.as_independent(S.Pi)
if m in [S.Pi/2, S.Pi]:
return sin(m)*cos(x)+cos(m)*sin(x)
# normalize sin(-x-y) to -sin(x+y)
if arg.args[0].is_Mul:
if arg.args[0].args[0].is_negative:
# e.g. arg = -x - y
if (-arg).args[0].is_Mul:
if (-arg).args[0].args[0].is_negative:
# This is to prevent infinite recursion in
# the case sin(-x+y), for which
# -arg = -y + x. See also #838 for the
# root of the problem here.
return
# convert sin(-x-y) to -sin(x+y)
return -cls(-arg)
if arg.args[0].is_negative:
if (-arg).args[0].is_negative:
# This is to avoid infinite recursion in the case
# sin(-x-1)
return
return -cls(-arg)
if isinstance(arg, asin):
return arg.args[0]
if isinstance(arg, atan):
x = arg.args[0]
return x / sqrt(1 + x**2)
if isinstance(arg, acos):
x = arg.args[0]
return sqrt(1 - x**2)
if isinstance(arg, acot):
x = arg.args[0];
return 1 / (sqrt(1 + 1 / x**2) * x)