def random_poly(x, n, inf, sup, domain=ZZ, polys=False): """Return a polynomial of degree ``n`` with coefficients in ``[inf, sup]``. """ poly = Poly(dup_random(n, inf, sup, domain), x, domain=domain) if not polys: return poly.as_expr() else: return poly
def test_dup_random(): f = dup_random(0, -10, 10, ZZ) assert dup_degree(f) == 0 assert all([ -10 <= c <= 10 for c in f ]) f = dup_random(1, -20, 20, ZZ) assert dup_degree(f) == 1 assert all([ -20 <= c <= 20 for c in f ]) f = dup_random(2, -30, 30, ZZ) assert dup_degree(f) == 2 assert all([ -30 <= c <= 30 for c in f ]) f = dup_random(3, -40, 40, ZZ) assert dup_degree(f) == 3 assert all([ -40 <= c <= 40 for c in f ])
def random_poly(x, n, inf, sup, domain=ZZ, polys=False): """Generates a polynomial of degree ``n`` with coefficients in ``[inf, sup]``. Parameters ---------- x `x` is the independent term of polynomial n : int `n` decides the order of polynomial inf Lower limit of range in which coefficients lie sup Upper limit of range in which coefficients lie domain : optional Decides what ring the coefficients are supposed to belong. Default is set to Integers. polys : bool, optional ``polys=True`` returns an expression, otherwise (default) returns an expression. """ poly = Poly(dup_random(n, inf, sup, domain), x, domain=domain) return poly if polys else poly.as_expr()