(expr, opt)
return poly, opt
Construct a polynomial from an expression.
Construct a polynomial from an expression.
Construct a polynomial from an expression .
def _poly_from_expr(expr, opt):
    """Construct a polynomial from an expression. """
    orig, expr = expr, sympify(expr)

    if not isinstance(expr, Basic):
        raise PolificationFailed(opt, orig, expr)
    elif expr.is_Poly:
        poly = expr.__class__._from_poly(expr, opt)

        opt.gens = poly.gens
        opt.domain = poly.domain

        if opt.polys is None:
            opt.polys = True

        return poly, opt
    elif opt.expand:
        expr = expr.expand()

    try:
        rep, opt = _dict_from_expr(expr, opt)
    except GeneratorsNeeded:
        raise PolificationFailed(opt, orig, expr)

    monoms, coeffs = list(zip(*list(rep.items())))
    domain = opt.domain

    if domain is None:
        opt.domain, coeffs = construct_domain(coeffs, opt=opt)
    else:
        coeffs = list(map(domain.from_sympy, coeffs))

    rep = dict(list(zip(monoms, coeffs)))
    poly = Poly._from_dict(rep, opt)

    if opt.polys is None:
        opt.polys = False

    return poly, opt
def _poly_from_expr ( expr , opt ) : orig , expr = expr , sympify ( expr ) if not isinstance ( expr , Basic ) : raise PolificationFailed ( opt , orig , expr ) elif expr . is_Poly : poly = expr . __class__ . _from_poly ( expr , opt ) opt . gens = poly . gens opt . domain = poly . domain if opt . polys is None : opt . polys = True return poly , opt elif opt . expand : expr = expr . expand ( ) try : rep , opt = _dict_from_expr ( expr , opt ) except GeneratorsNeeded : raise PolificationFailed ( opt , orig , expr ) monoms , coeffs = list ( zip ( * list ( rep . items ( ) ) ) ) domain = opt . domain if domain is None : opt . domain , coeffs = construct_domain ( coeffs , opt = opt ) else : coeffs = list ( map ( domain . from_sympy , coeffs ) ) rep = dict ( list ( zip ( monoms , coeffs ) ) ) poly = Poly . _from_dict ( rep , opt ) if opt . polys is None : opt . polys = False return poly , opt