本文整理汇总了Python中sage.rings.all.ComplexIntervalField类的典型用法代码示例。如果您正苦于以下问题:Python ComplexIntervalField类的具体用法?Python ComplexIntervalField怎么用?Python ComplexIntervalField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComplexIntervalField类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _eval_
def _eval_(self, x):
"""
INPUT:
- ``x`` - a real number or a symbolic expression
EXAMPLES::
sage: dirac_delta(1)
0
sage: dirac_delta(0)
dirac_delta(0)
sage: dirac_delta(x)
dirac_delta(x)
sage: dirac_delta(exp(-10000000000000000000))
0
Evaluation test::
sage: dirac_delta(x).subs(x=1)
0
"""
try:
approx_x = ComplexIntervalField()(x)
if bool(approx_x.imag() == 0): # x is real
if bool(approx_x.real() == 0): # x is zero
return None
else:
return 0
except Exception: # x is symbolic
pass
return None
示例2: _evalf_
def _evalf_(self, x, **kwds):
"""
TESTS:
Check that :trac:`16587` is fixed::
sage: M = sgn(3/2, hold=True); M
sgn(3/2)
sage: M.n()
1
sage: h(x) = sgn(x)
sage: h(pi).numerical_approx()
1.00000000000000
"""
if hasattr(x,'sign'): # First check if x has a sign method
return x.sign()
if hasattr(x,'sgn'): # or a sgn method
return x.sgn()
approx_x = ComplexIntervalField()(x)
if bool(approx_x.imag() == 0): # x is real
if bool(approx_x.real() == 0): # x is zero
return ZZ(0)
# Now we have a non-zero real
if bool((approx_x**(0.5)).imag() == 0): # Check: x > 0
return ZZ(1)
else:
return ZZ(-1)
raise ValueError("Numeric evaluation of symbolic expression")
示例3: _is_numerically_zero_CIF
def _is_numerically_zero_CIF(x):
from sage.rings.all import ComplexIntervalField
try:
approx_x = ComplexIntervalField()(x)
if bool(approx_x.imag() == 0) and bool(approx_x.real() == 0):
return True
except:
return False
示例4: _evalf_
def _evalf_(self, x, **kwds):
"""
TESTS::
sage: h(x) = unit_step(x)
sage: h(pi).numerical_approx()
1.00000000000000
"""
approx_x = ComplexIntervalField()(x)
if bool(approx_x.imag() == 0): # x is real
if bool(approx_x.real() == 0): # x is zero
return 1
# Now we have a non-zero real
if bool((approx_x**(0.5)).imag() == 0): # Check: x > 0
return 1
else:
return 0
raise ValueError("Numeric evaluation of symbolic expression")