Skip to content

Sparse

Sparse polynomials.

>>> from poly import polysval
>>> p = {0:1, 3:2} #p(x)=2*x^3+1
>>> polysval(p, 5)

Prefixed by polys... (poly - sparse).

All functions accept polynomials and return them as dicts (monomial-exponent:coefficient).

Index keys are expected to be integers.

Docstring conventions

Summary

Math notation (vector notation if possible, index notation, domain & codomain)

More information ("More efficient than ...").

Complexity

For a polynomial with \(n\) elements there will be - \(x\) scalar additions (add), ...

Notes

Design choices

See also

Similar functions

References

Wikipedia, numpy, ...

creation

polyszero = vecszero

Zero polynomial.

\[ 0 \]

An empty dict: {}.

See also

polysone = {0: 1}

Constant one polynomial.

\[ 1 \]
See also

polysx = {1: 1}

Identity polynomial.

\[ x \]
See also

polysmono(i, c=1)

Return a monomial of degree n.

\[ cx^n \]
See also
Source code in poly\sparse\creation.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def polysmono(i, c=1):
    r"""Return a monomial of degree `n`.

    $$
        cx^n
    $$

    See also
    --------
    - other constants: [`polyszero`][poly.sparse.creation.polyszero], [`polysone`][poly.sparse.creation.polysone], [`polysx`][poly.sparse.creation.polysx]
    - for all monomials: [`polysmonos`][poly.sparse.creation.polysmonos]
    - wraps: [`vector.vecsbasis`](https://goessl.github.io/vector/sparse/#vector.sparse.creation.vecsbasis)
    """
    return vecsbasis(i, c=c) if i>=0 else polyszero

polysmonos(start=0, c=1)

Yield all monomials.

\[ \left(x^n\right)_\mathbb{n\in\mathbb{N_0}} = \left(1, x, x^2, \dots \right) \]
See also
Source code in poly\sparse\creation.py
67
68
69
70
71
72
73
74
75
76
77
78
79
def polysmonos(start=0, c=1):
    r"""Yield all monomials.

    $$
        \left(x^n\right)_\mathbb{n\in\mathbb{N_0}} = \left(1, x, x^2, \dots \right)
    $$

    See also
    --------
    - for single monomial: [`polysmono`][poly.sparse.creation.polysmono]
    - wraps: [`vector.vecsbases`](https://goessl.github.io/vector/sparse/#vector.sparse.creation.vecsbases)
    """
    yield from vecsbases(start=start, c=c)

polysrand(n)

Return a random polynomial of degree n.

\[ \sum_ka_kx^k \quad a_k\sim\mathcal{U}^n([0, 1[) \]

The coefficients are sampled from a uniform distribution in [0, 1[.

See also
Source code in poly\sparse\creation.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def polysrand(n):
    r"""Return a random polynomial of degree `n`.

    $$
        \sum_ka_kx^k \quad a_k\sim\mathcal{U}^n([0, 1[)
    $$

    The coefficients are sampled from a uniform distribution in `[0, 1[`.

    See also
    --------
    - wraps: [`vector.vecsrand`](https://goessl.github.io/vector/sparse/#vector.sparse.creation.vecsrand)
    """
    return vecsrand(n+1) if n>=0 else polyszero

polysrandn(n, normed=True, mu=0, sigma=1, weights=None)

Return a random polynomial of degree n.

\[ \sum_{k=0}^na_kx^k \quad a_k\sim\mathcal{N}(\mu, \sigma) \]

The coefficients are sampled from a normal distribution.

Normed with respect to the euclidian vector norm \(\sum_k|a_k|^2\).

See also
Source code in poly\sparse\creation.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def polysrandn(n, normed=True, mu=0, sigma=1, weights=None):
    r"""Return a random polynomial of degree `n`.

    $$
        \sum_{k=0}^na_kx^k \quad a_k\sim\mathcal{N}(\mu, \sigma)
    $$

    The coefficients are sampled from a normal distribution.

    Normed with respect to the euclidian vector norm $\sum_k|a_k|^2$.

    See also
    --------
    - wraps: [`vector.vecsrandn`](https://goessl.github.io/vector/functional/#vector.functional.creation.vecsrandn)
    """
    return vecsrandn(n+1, normed=normed, mu=mu, sigma=sigma) if n>=0 else polyszero

polysfromroots(*xs, one=1)

Return the polynomial with the given roots.

\[ \prod_k(x-x_k) \]
Source code in poly\sparse\creation.py
113
114
115
116
117
118
119
120
121
122
123
def polysfromroots(*xs, one=1):
    r"""Return the polynomial with the given roots.

    $$
        \prod_k(x-x_k)
    $$
    """
    r = {0:one}
    for x in xs:
        r = polyssub(polysmulx(r), polysscalarrmul(x, r))
    return r

utility

polysdeg(p)

Return the degree of a polynomial.

\[ \deg(p) \]

Doesn't handle leading zeros, use polystrim if needed.

\(\deg(0)=-1\) is used for the empty zero polynomial.

Source code in poly\sparse\utility.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
def polysdeg(p):
    r"""Return the degree of a polynomial.

    $$
        \deg(p)
    $$

    Doesn't handle leading zeros, use [`polystrim`][poly.sparse.utility.polystrim]
    if needed.

    $\deg(0)=-1$ is used for the empty zero polynomial.
    """
    return max(p.keys(), default=-1)

polyseq(p, q)

Return if two polynomials are equal.

\[ p \overset{?}{=} q \]
See also
Source code in poly\sparse\utility.py
23
24
25
26
27
28
29
30
31
32
33
34
def polyseq(p, q):
    r"""Return if two polynomials are equal.

    $$
        p \overset{?}{=} q
    $$

    See also
    --------
    - wraps: [`vecseq`](https://goessl.github.io/vector/sparse/#vector.sparse.utility.vecseq)
    """
    return vecseq(p, q)

polystrim(p, tol=None)

Remove all near zero (abs(v_i)<=tol) coefficients.

Source code in poly\sparse\utility.py
36
37
38
def polystrim(p, tol=None):
    """Remove all near zero (`abs(v_i)<=tol`) coefficients."""
    return vecstrim(p, tol=tol)

evaluation

polysval(p, x)

Return the value of polynomial p evaluated at point x.

\[ p(x) \]
See also
Source code in poly\sparse\evaluation.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def polysval(p, x):
    """Return the value of polynomial `p` evaluated at point `x`.

    $$
        p(x)
    $$

    See also
    --------
    - implementations: [`polyval_naive`][poly.standard.polyval_naive],
    [`polyval_iterative`][poly.standard.polyval_iterative],
    [`polyval_horner`][poly.standard.polyval_horner]
    - for consecutive monomials: [`polyvals`][poly.standard.polyvals]
    - for $x=0$: [`polyvalzero`][poly.standard.polyvalzero]
    - for polynomial arguments: [`polycom`][poly.standard.polycom]
    """
    return sumprod_default(p.values(), map(pow, repeat(x), p.keys()), default=type(x)(0))

polysvalzero(p, zero=0)

Return the value of polynomial p evaluated at point 0.

\[ p(0) \]

More efficient than polysval(p, 0).

See also
Source code in poly\sparse\evaluation.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def polysvalzero(p, zero=0):
    """Return the value of polynomial `p` evaluated at point 0.

    $$
        p(0)
    $$

    More efficient than `polysval(p, 0)`.

    See also
    --------
    - for any argument: [`polysval`][poly.sparse.evaluation.polysval]
    """
    return p.get(0, zero)

polyscom(p, q)

Return the polynomial composition of p & q.

\[ p\circ q \]
See also
Source code in poly\sparse\evaluation.py
44
45
46
47
48
49
50
51
52
53
54
55
56
def polyscom(p, q):
    r"""Return the polynomial composition of `p` & `q`.

    $$
        p\circ q
    $$

    See also
    --------
    - for $q=x-s$: [`polysshift`][poly.sparse.evaluation.polysshift]
    - for scalar arguments: [`polysval`][poly.sparse.evaluation.polysval]
    """
    return polysadd(*(polysscalarrmul(pi, polyspow(q, i)) for i, pi in p.items()))

polysshift(p, s, one=1)

Return the polynomial p shifted by s on the abscissa.

\[ p(x - s) \]
See also
Source code in poly\sparse\evaluation.py
58
59
60
61
62
63
64
65
66
67
68
69
def polysshift(p, s, one=1):
    """Return the polynomial `p` shifted by `s` on the abscissa.

    $$
        p(x - s)
    $$

    See also
    --------
    - for polynomial argument: [`polyscom`][poly.sparse.evaluation.polyscom]
    """
    return polyscom(p, {0:-s, 1:one})

polysscale(p, a)

Return the polynomial p scaled by 1/a on the abscissa.

\[ p(ax) \]

More efficient than polyscom(p, polysscalarmul(a, polysx)).

See also
Source code in poly\sparse\evaluation.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def polysscale(p, a):
    """Return the polynomial `p` scaled by 1/`a` on the abscissa.

    $$
        p(ax)
    $$

    More efficient than `polyscom(p, polysscalarmul(a, polysx))`.

    See also
    --------
    - for polynomial argument: [`polyscom`][poly.sparse.evaluation.polyscom]
    """
    return {i:a**i*pi for i, pi in p.items()}

arithmetic

polyspos(p)

Return the polynomial with the unary positive operator applied.

\[ +p \]
See also
Source code in poly\sparse\arithmetic.py
13
14
15
16
17
18
19
20
21
22
23
24
def polyspos(p):
    """Return the polynomial with the unary positive operator applied.

    $$
        +p
    $$

    See also
    --------
    - wraps: [`vecspos`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecspos)
    """
    return vecspos(p)

polysneg(p)

Return the polynomial with the unary negative operator applied.

\[ -p \]
See also
Source code in poly\sparse\arithmetic.py
26
27
28
29
30
31
32
33
34
35
36
37
def polysneg(p):
    """Return the polynomial with the unary negative operator applied.

    $$
        -p
    $$

    See also
    --------
    - wraps: [`vecsneg`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsneg)
    """
    return vecsneg(p)

polysadd(*ps)

Return the sum of polynomials.

\[ p_0+p_1+\cdots \]
See also
Source code in poly\sparse\arithmetic.py
39
40
41
42
43
44
45
46
47
48
49
50
def polysadd(*ps):
    r"""Return the sum of polynomials.

    $$
        p_0+p_1+\cdots
    $$

    See also
    --------
    - wraps: [`vecsadd`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsadd)
    """
    return vecsadd(*ps)

polysaddc(p, c, n=0)

Return the sum of polynomial p and a monomial of degree n.

\[ p+cx^n \]
See also
Source code in poly\sparse\arithmetic.py
52
53
54
55
56
57
58
59
60
61
62
63
def polysaddc(p, c, n=0):
    """Return the sum of polynomial `p` and a monomial of degree `n`.

    $$
        p+cx^n
    $$

    See also
    --------
    - wraps: [`vecsaddc`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsaddc)
    """
    return vecsaddc(p, c=c, i=n)

polyssub(p, q)

Return the difference of two polynomials.

\[ p-q \]
See also
Source code in poly\sparse\arithmetic.py
65
66
67
68
69
70
71
72
73
74
75
76
def polyssub(p, q):
    r"""Return the difference of two polynomials.

    $$
        p-q
    $$

    See also
    --------
    - wraps: [`vecssub`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecssub)
    """
    return vecssub(p, q)

polyssubc(p, c, n=0)

Return the difference of polynomial p and a monomial of degree n.

\[ p-cx^n \]
See also
Source code in poly\sparse\arithmetic.py
78
79
80
81
82
83
84
85
86
87
88
89
def polyssubc(p, c, n=0):
    """Return the difference of polynomial `p` and a monomial of degree `n`.

    $$
        p-cx^n
    $$

    See also
    --------
    - wraps: [`vecssubc`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecssubc)
    """
    return vecssubc(p, c=c, i=n)

polysscalarmul(p, a)

Return the product.

\[ pa \]
See also
Source code in poly\sparse\arithmetic.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def polysscalarmul(p, a):
    """Return the product.

    $$
        pa
    $$

    See also
    --------
    - wraps: [`vecsmul`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsmul)
    """
    return vecsmul(p, a)

polysscalarrmul(a, p)

Return the product.

\[ ap \]
See also
Source code in poly\sparse\arithmetic.py
104
105
106
107
108
109
110
111
112
113
114
115
def polysscalarrmul(a, p):
    """Return the product.

    $$
        ap
    $$

    See also
    --------
    - wraps: [`vecsrmul`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsrmul)
    """
    return vecsrmul(a, p)

polysscalartruediv(p, a)

Return the true division of a polynomial and a scalar.

\[ \frac{p}{a} \]
See also
Source code in poly\sparse\arithmetic.py
117
118
119
120
121
122
123
124
125
126
127
128
def polysscalartruediv(p, a):
    r"""Return the true division of a polynomial and a scalar.

    $$
        \frac{p}{a}
    $$

    See also
    --------
    - wraps: [`vecstruediv`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecstruediv)
    """
    return vecstruediv(p, a)

polysscalarfloordiv(p, a)

Return the floor division of a polynomial and a scalar.

\[ \sum_k\left\lfloor\frac{a_k}{a}\right\rfloor x^k \]
See also
Source code in poly\sparse\arithmetic.py
130
131
132
133
134
135
136
137
138
139
140
141
def polysscalarfloordiv(p, a):
    r"""Return the floor division of a polynomial and a scalar.

    $$
        \sum_k\left\lfloor\frac{a_k}{a}\right\rfloor x^k
    $$

    See also
    --------
    - wraps: [`vecsfloordiv`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsfloordiv)
    """
    return vecsfloordiv(p, a)

polysscalarmod(p, a)

Return the elementwise mod of a polynomial and a scalar.

\[ \sum_k\left(a_k \mod a\right)x^k \]
See also
Source code in poly\sparse\arithmetic.py
143
144
145
146
147
148
149
150
151
152
153
154
def polysscalarmod(p, a):
    r"""Return the elementwise mod of a polynomial and a scalar.

    $$
        \sum_k\left(a_k \mod a\right)x^k
    $$

    See also
    --------
    - wraps: [`vecsmod`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsmod)
    """
    return vecsmod(p, a)

polysscalardivmod(p, a)

Return the elementwise divmod of a polynomial and a scalar.

\[ \sum_k\left\lfloor\frac{a_k}{a}\right\rfloor x^k, \ \sum_k\left(a_k \mod a\right)x^k \]
See also
Source code in poly\sparse\arithmetic.py
156
157
158
159
160
161
162
163
164
165
166
167
def polysscalardivmod(p, a):
    r"""Return the elementwise divmod of a polynomial and a scalar.

    $$
        \sum_k\left\lfloor\frac{a_k}{a}\right\rfloor x^k, \ \sum_k\left(a_k \mod a\right)x^k
    $$

    See also
    --------
    - wraps: [`vecsdivmod`](https://goessl.github.io/vector/sparse/#vector.sparse.vector_space.vecsdivmod)
    """
    return vecsdivmod(p, a)

polysmul(*ps, method='naive', one=1)

Return the product of polynomials.

\[ p_0 p_1 \cdots \]

Available methods are

See also
Source code in poly\sparse\arithmetic.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
def polysmul(*ps, method='naive', one=1):
    r"""Return the product of polynomials.

    $$
        p_0 p_1 \cdots
    $$

    Available methods are

    - [`naive`][poly.sparse.arithmetic.polysmul_naive].

    See also
    --------
    - implementations: [`polysmul_naive`][poly.sparse.arithmetic.polysmul_naive]
    - for scalar factor: [`polysscalarmul`][poly.sparse.arithmetic.polysscalarmul]
    - for monomial factor: [`polysmulx`][poly.sparse.arithmetic.polysmulx]
    """
    match method:
        case 'naive':
            return reduce_default(polysmul_naive, ps, default={0:one})
        case _:
            raise ValueError('Invalid method')

polysmul_naive(p, q)

Return the product of two polynomials.

\[ pq \]

Uses naive multiplication and summation.

See also
Source code in poly\sparse\arithmetic.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
def polysmul_naive(p, q):
    """Return the product of two polynomials.

    $$
        pq
    $$

    Uses naive multiplication and summation.

    See also
    --------
    - for any implementation: [`polysmul`][poly.sparse.arithmetic.polysmul]
    """
    r = {}
    for i, pi in p.items():
        for j, qj in q.items():
            if i+j not in r:
                r[i+j] = pi * qj
            else:
                r[i+j] += pi * qj
    return r

polysmulx(p, n=1)

Return the product of polynomial p and a monomial of degree n.

\[ px^n \]

More efficient than polysmul(p, polysmonom(n)).

Complexity

There are no scalar arithmetic operations.

See also
Source code in poly\sparse\arithmetic.py
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def polysmulx(p, n=1):
    """Return the product of polynomial `p` and a monomial of degree `n`.

    $$
        px^n
    $$

    More efficient than `polysmul(p, polysmonom(n))`.

    Complexity
    ----------
    There are no scalar arithmetic operations.

    See also
    --------
    - for polynomial factor: [`polysmul`][poly.sparse.arithmetic.polysmul]
    - wraps: [`vector.vecsrshift`](https://goessl.github.io/vector/sparse/#vector.sparse.utility.vecsrshift)
    """
    return vecsrshift(p, n)

polyspow(p, n, method='naive')

Return the polynomial p raised to the nonnegative n-th power.

\[ p^n \]

Available methods are

TODO: mod parameter

See also
Source code in poly\sparse\arithmetic.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
def polyspow(p, n, method='naive'):
    """Return the polynomial `p` raised to the nonnegative `n`-th power.

    $$
        p^n
    $$

    Available methods are 

    - [`naive`][poly.sparse.arithmetic.polyspow_naive] &
    - [`binary`][poly.sparse.arithmetic.polyspow_binary].

    TODO: mod parameter

    See also
    --------
    - implementations: [`polyspow_naive`][poly.sparse.arithmetic.polyspow_naive],
    [`polyspow_binary`][poly.sparse.arithmetic.polyspow_binary]
    - for sequence of powers: [`polyspows`][poly.sparse.arithmetic.polyspows]
    """
    match method:
        case 'naive':
            return polyspow_naive(p, n)
        case 'binary':
            return polyspow_binary(p, n)
        case _:
            raise ValueError('Invalid method')

polyspow_naive(p, n, one=1)

Return the polynomial p raised to the nonnegative n-th power.

\[ p^n \]

Uses repeated multiplication.

See also
Source code in poly\sparse\arithmetic.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def polyspow_naive(p, n, one=1):
    r"""Return the polynomial `p` raised to the nonnegative `n`-th power.

    $$
        p^n
    $$

    Uses repeated multiplication.

    See also
    --------
    - for any implementation: [`polyspow`][poly.sparse.arithmetic.polyspow]
    - other implementations:
    [`polyspow_binary`][poly.sparse.arithmetic.polyspow_binary]
    - uses: [`polyspows`][poly.sparse.arithmetic.polyspows]
    """
    return next(polyspows(p, start=n, one=one))

polyspow_binary(p, n, one=1)

Return the polynomial p raised to the nonnegative n-th power.

\[ p^n \]

Uses exponentiation by squaring.

See also
References
Source code in poly\sparse\arithmetic.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
def polyspow_binary(p, n, one=1):
    r"""Return the polynomial `p` raised to the nonnegative `n`-th power.

    $$
        p^n
    $$

    Uses exponentiation by squaring.

    See also
    --------
    - for any implementation: [`polyspow`][poly.sparse.arithmetic.polyspow]
    - other implementations:
    [`polyspow_naive`][poly.sparse.arithmetic.polyspow_naive]

    References
    ----------
    - [Wikipedia - Exponentiation by squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring)
    - Sequence $C(k)$: [A056791](https://oeis.org/A056791)
    """
    if n == 0:
        return {0:one} #polysone
    r = None
    while n:
        if n % 2 == 1:
            r = polysmul_naive(r, p) if r is not None else p
        p = polysmul_naive(p, p)
        n //= 2
    return r

polyspows(p, start=0, one=1)

Yield the powers of the polynomial p.

\[ (p^n)_{n\in\mathbb{N}_0} = (1, p, p^2, \dots) \]

Uses iterative multiplication to calculate powers consecutively.

See also
Source code in poly\sparse\arithmetic.py
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
def polyspows(p, start=0, one=1):
    r"""Yield the powers of the polynomial `p`.

    $$
        (p^n)_{n\in\mathbb{N}_0} = (1, p, p^2, \dots)
    $$

    Uses iterative multiplication to calculate powers consecutively.

    See also
    --------
    - used by: [`polyspow_naive`][poly.sparse.arithmetic.polyspow_naive], [`polyscom_iterative`][poly.sparse.evaluation.polyscom]
    - for scalar arguments: [`polyvals`][poly.standard.evaluation.polyvals]
    """
    if start <= 0:
        yield {0:one} #polysone
    yield (q := reduce_default(polysmul_naive, repeat(p, start), initial=MISSING, default=p))
    while True:
        q = polysmul_naive(q, p)
        yield q

calculus

polysder(p, k=1)

Return the k-th derivative of polynomial p.

\[ p^{(k)} \]
Source code in poly\sparse\calculus.py
11
12
13
14
15
16
17
18
def polysder(p, k=1):
    """Return the `k`-th derivative of polynomial `p`.

    $$
        p^{(k)}
    $$
    """
    return {i-k:perm(i, k)*pi for i, pi in p.items() if i-k>=0}

polysantider(p, c=0, b=0)

Return the antiderivative of polynomial p.

\[ \int_b^xp(y)\,\mathrm{d}y+c \]
Source code in poly\sparse\calculus.py
20
21
22
23
24
25
26
27
28
def polysantider(p, c=0, b=0):
    r"""Return the antiderivative of polynomial `p`.

    $$
        \int_b^xp(y)\,\mathrm{d}y+c
    $$
    """
    P = {i+1:pi/(i+1) for i, pi in p.items()}
    return polysaddc(P, c-polysval(P, b) if b else c)

conversion

polystod(p, zero=0)

Return a sparse polynomial (dict) as a dense polynomial (tuple).

Source code in poly\sparse\conversion.py
11
12
13
def polystod(p, zero=0):
    """Return a sparse polynomial (`dict`) as a dense polynomial (`tuple`)."""
    return vecstod(p, zero=zero)

polydtos(p)

Return a dense polynomial (tuple) as a sparse polynomial (dict).

The resulting dict is not trimmed.

Source code in poly\sparse\conversion.py
15
16
17
18
19
20
def polydtos(p):
    """Return a dense polynomial (`tuple`) as a sparse polynomial (`dict`).

    The resulting `dict` is not [trimmed][poly.sparse.utility.polystrim].
    """
    return vecdtos(p)

polyssympify(p, gen=x)

Return the coefficient mapping p as a sympy.Poly.

Source code in poly\sparse\conversion.py
22
23
24
def polyssympify(p, gen=x):
    """Return the coefficient mapping `p` as a [`sympy.Poly`](https://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.polytools.Poly)."""
    return Poly.from_dict(p, gen)

polysunsympify(p, gen=x)

Return sympy.Poly(p) as a coefficient dict.

Source code in poly\sparse\conversion.py
26
27
28
def polysunsympify(p, gen=x):
    """Return [`sympy.Poly(p)`](https://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.polytools.Poly) as a coefficient `dict`."""
    return {i[0]:pi for i, pi in p.as_dict(native=True).items()}