Initial SymPy benchmark suite
[sympy.git] / sympy / polys / wrappers.py
blobeee041b8c1465301f4019b603af2e39d9cc01d5d
2 from polynomial import Poly
4 def LexPoly(*args):
5 """Returns a polynomial with lexicographic order of terms. """
6 return Poly(*args, **{ 'order' : 'lex' })
8 from algorithms import poly_div, poly_pdiv, poly_groebner, poly_lcm, poly_gcd, \
9 poly_half_gcdex, poly_gcdex, poly_sqf, poly_resultant, poly_subresultants, \
10 poly_decompose
12 from rootfinding import poly_factors, poly_sturm
14 def poly_quo(f, g, *symbols):
15 """Wrapper for poly_div() """
16 return poly_div(f, g, *symbols)[0]
18 def poly_rem(f, g, *symbols):
19 """Wrapper for poly_div() """
20 return poly_div(f, g, *symbols)[1]
22 def poly_pquo(f, g, *symbols):
23 """Wrapper for poly_pdiv() """
24 return poly_pdiv(f, g, *symbols)[0]
26 def poly_prem(f, g, *symbols):
27 """Wrapper for poly_pdiv() """
28 return poly_pdiv(f, g, *symbols)[1]
30 def _conv_args(n, args):
31 symbols = args[n:]
33 if len(symbols) == 1 and isinstance(symbols[0], (tuple, list)):
34 return args[:n] + tuple(symbols[0])
35 else:
36 return args
38 def _map_basic(f, n, *args, **kwargs):
39 result = f(*_conv_args(n, args), **kwargs)
41 if isinstance(result, (list, tuple, set)):
42 return result.__class__(g.as_basic() for g in result)
43 else:
44 return result.as_basic()
46 _funcs = {
47 'quo' : 2,
48 'rem' : 2,
49 'pdiv' : 2,
50 'pquo' : 2,
51 'prem' : 2,
52 'groebner' : 1,
53 'lcm' : 2,
54 'gcd' : 2,
55 'gcdex' : 2,
56 'half_gcdex' : 2,
57 'subresultants' : 2,
58 'resultant' : 2,
59 'sqf' : 1,
60 'decompose' : 1,
61 'factors' : 1,
62 'sturm' : 1,
65 _func_def = \
66 """
67 def %s(*args, **kwargs):
68 return _map_basic(poly_%s, %d, *args, **kwargs)
70 %s.__doc__ = poly_%s.__doc__
71 """
73 for _func, _n in _funcs.iteritems():
74 exec _func_def % (_func, _func, _n, _func, _func)
76 def div(*args, **kwargs):
77 q, r = poly_div(*_conv_args(2, args), **kwargs)
79 if type(q) is not list:
80 q = q.as_basic()
81 else:
82 q = [ p.as_basic() for p in q ]
84 return q, r.as_basic()
86 div.__doc__ = poly_div.__doc__