本文整理汇总了Python中sympy.polys.Poly.get_domain方法的典型用法代码示例。如果您正苦于以下问题:Python Poly.get_domain方法的具体用法?Python Poly.get_domain怎么用?Python Poly.get_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.polys.Poly
的用法示例。
在下文中一共展示了Poly.get_domain方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reduce_poly_inequalities
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import get_domain [as 别名]
def reduce_poly_inequalities(exprs, gen, assume=True, relational=True):
"""Reduce a system of polynomial inequalities with rational coefficients. """
exact = True
polys = []
for _exprs in exprs:
_polys = []
for expr in _exprs:
if isinstance(expr, tuple):
expr, rel = expr
else:
if expr.is_Relational:
expr, rel = expr.lhs - expr.rhs, expr.rel_op
else:
expr, rel = expr, '=='
poly = Poly(expr, gen)
if not poly.get_domain().is_Exact:
poly, exact = poly.to_exact(), False
domain = poly.get_domain()
if not (domain.is_ZZ or domain.is_QQ):
raise NotImplementedError("inequality solving is not supported over %s" % domain)
_polys.append((poly, rel))
polys.append(_polys)
solution = solve_poly_inequalities(polys)
if isinstance(solution, Union):
intervals = list(solution.args)
elif isinstance(solution, Interval):
intervals = [solution]
else:
intervals = []
if not exact:
intervals = map(interval_evalf, intervals)
if not relational:
return intervals
real = ask(gen, 'real', assume)
def relationalize(gen):
return Or(*[ i.as_relational(gen) for i in intervals ])
if not real:
result = And(relationalize(re(gen)), Eq(im(gen), 0))
else:
result = relationalize(gen)
return result
示例2: reduce_poly_inequalities
# 需要导入模块: from sympy.polys import Poly [as 别名]
# 或者: from sympy.polys.Poly import get_domain [as 别名]
def reduce_poly_inequalities(exprs, gen, assume=True, relational=True):
"""Reduce a system of polynomial inequalities with rational coefficients. """
exact = True
polys = []
for _exprs in exprs:
_polys = []
for expr in _exprs:
if isinstance(expr, tuple):
expr, rel = expr
else:
if expr.is_Relational:
expr, rel = expr.lhs - expr.rhs, expr.rel_op
else:
expr, rel = expr, "=="
poly = Poly(expr, gen)
if not poly.get_domain().is_Exact:
poly, exact = poly.to_exact(), False
domain = poly.get_domain()
if not (domain.is_ZZ or domain.is_QQ):
raise NotImplementedError("inequality solving is not supported over %s" % domain)
_polys.append((poly, rel))
polys.append(_polys)
solution = solve_poly_inequalities(polys)
if not exact:
solution = solution.evalf()
if not relational:
return solution
real = ask(Q.real(gen), assumptions=assume)
if not real:
result = And(solution.as_relational(re(gen)), Eq(im(gen), 0))
else:
result = solution.as_relational(gen)
return result