1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Copyright © 2026 Mikhail Hogrefe
//
// This file is part of Malachite.
//
// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
/// Implementations of [`Add`](core::ops::Add) and [`AddAssign`](core::ops::AddAssign), for adding
/// two polynomials.
/// Implementations of [`AddTruncated`](malachite_base::polynomial::AddTruncated) and
/// [`AddTruncatedAssign`](malachite_base::polynomial::AddTruncatedAssign), for adding two
/// polynomials and keeping only their low coefficients.
/// Implementations of [`CanonicalPrimitivePart`](
/// malachite_base::num::arithmetic::traits::CanonicalPrimitivePart) and
/// [`ContentAndCanonicalPrimitivePart`](
/// malachite_base::num::arithmetic::traits::ContentAndCanonicalPrimitivePart) for
/// [`RationalPolynomial`](super::RationalPolynomial)s, which give the primitive part with a
/// non-negative leading coefficient.
/// Implementations of
/// [`CanonicalizeUnit`](malachite_base::num::arithmetic::traits::CanonicalizeUnit) and
/// [`CanonicalizeUnitAssign`](malachite_base::num::arithmetic::traits::CanonicalizeUnitAssign),
/// which bring a polynomial into canonical unit form.
/// Implementations of [`ComposePowerOfX`](malachite_base::polynomial::ComposePowerOfX) and
/// [`ComposePowerOfXAssign`](malachite_base::polynomial::ComposePowerOfXAssign), for substituting a
/// power of the variable into a polynomial.
/// Implementations of [`Content`](malachite_base::num::arithmetic::traits::Content),
/// [`PrimitivePart`](malachite_base::num::arithmetic::traits::PrimitivePart), and
/// [`ContentAndPrimitivePart`](malachite_base::num::arithmetic::traits::ContentAndPrimitivePart)
/// for [`RationalPolynomial`](super::RationalPolynomial)s.
/// Implementations of [`DeflatePowerOfX`](malachite_base::polynomial::DeflatePowerOfX) and
/// [`DeflatePowerOfXAssign`](malachite_base::polynomial::DeflatePowerOfXAssign), for undoing the
/// substitution of a power of the variable into a polynomial.
/// Implementations of [`Derivative`](malachite_base::polynomial::Derivative) and
/// [`DerivativeAssign`](malachite_base::polynomial::DerivativeAssign), for differentiating a
/// polynomial.
/// Implementations of [`DivPowerOfX`](malachite_base::polynomial::DivPowerOfX) and
/// [`DivPowerOfXAssign`](malachite_base::polynomial::DivPowerOfXAssign), for dividing a polynomial
/// by a power of its variable and discarding the remainder.
/// Implementations of [`Evaluate`](malachite_base::polynomial::Evaluate) for
/// [`IntegerPolynomial`](malachite_nz::integer_polynomial::IntegerPolynomial)s and
/// [`RationalPolynomial`](super::RationalPolynomial)s at [`Rational`](crate::Rational)s, and for
/// [`RationalPolynomial`](super::RationalPolynomial)s at
/// [`Integer`](malachite_nz::integer::Integer)s.
/// An implementation of [`ExponentGcd`](malachite_base::polynomial::ExponentGcd), the greatest
/// common divisor of the exponents at which a polynomial has nonzero coefficients.
/// An implementation of [`Height`](malachite_base::num::arithmetic::traits::Height), the largest of
/// the heights of a polynomial's coefficients.
/// Implementations of [`Integral`](malachite_base::polynomial::Integral) and
/// [`IntegralAssign`](malachite_base::polynomial::IntegralAssign), for integrating a polynomial.
/// An implementation of [`IsUnit`](malachite_base::num::arithmetic::traits::IsUnit), a trait for
/// determining whether a number is a unit of its ring.
/// An implementation of [`L2NormSquared`](malachite_base::polynomial::L2NormSquared), the sum of
/// the squares of a polynomial's coefficients.
/// Implementations of [`MakeMonic`](malachite_base::polynomial::MakeMonic) and
/// [`MakeMonicAssign`](malachite_base::polynomial::MakeMonicAssign), which divide a polynomial by
/// its leading coefficient.
/// Implementations of [`Mul`](core::ops::Mul) and [`MulAssign`](core::ops::MulAssign), for
/// multiplying two polynomials.
/// Implementations of [`MulPowerOfX`](malachite_base::polynomial::MulPowerOfX) and
/// [`MulPowerOfXAssign`](malachite_base::polynomial::MulPowerOfXAssign), for multiplying a
/// polynomial by a power of its variable.
/// Implementations of [`MulTruncated`](malachite_base::polynomial::MulTruncated) and
/// [`MulTruncatedAssign`](malachite_base::polynomial::MulTruncatedAssign), for multiplying two
/// polynomials and keeping the low coefficients of the product.
/// Implementations of [`Neg`](core::ops::Neg) and
/// [`NegAssign`](malachite_base::num::arithmetic::traits::NegAssign), for negating a polynomial.
/// Implementations of [`NthDerivative`](malachite_base::polynomial::NthDerivative) and
/// [`NthDerivativeAssign`](malachite_base::polynomial::NthDerivativeAssign), for differentiating a
/// polynomial any number of times.
/// Implementations of [`Pow`](malachite_base::num::arithmetic::traits::Pow) and
/// [`PowAssign`](malachite_base::num::arithmetic::traits::PowAssign), for raising a polynomial to a
/// power.
/// Implementations of [`PowTruncated`](malachite_base::polynomial::PowTruncated) and
/// [`PowTruncatedAssign`](malachite_base::polynomial::PowTruncatedAssign), for raising a polynomial
/// to a power and keeping only the low coefficients of the power.
/// Left-shifting a [`RationalPolynomial`](super::RationalPolynomial) (multiplying it or dividing it
/// by a power of 2), keeping it in lowest terms.
///
/// # shl
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::basic::traits::Zero;
/// use malachite_q::rational_polynomial::RationalPolynomial;
///
/// assert_eq!((RationalPolynomial::ZERO << 10u8).to_string(), "0");
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 0u16).to_string(),
/// "1/3*x^2-3/4*x+5"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 2u32).to_string(),
/// "4/3*x^2-3*x+20"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 100u64).to_string(),
/// "1267650600228229401496703205376/3*x^2-950737950171172051122527404032*x+\
/// 6338253001141147007483516026880"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 3i8).to_string(),
/// "8/3*x^2-6*x+40"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << -2i16).to_string(),
/// "1/12*x^2-3/16*x+5/4"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << -100i64).to_string(),
/// "1/3802951800684688204490109616128*x^2-3/5070602400912917605986812821504*x+\
/// 5/1267650600228229401496703205376"
/// );
///
/// assert_eq!((&RationalPolynomial::ZERO << 10u8).to_string(), "0");
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 0u16).to_string(),
/// "1/3*x^2-3/4*x+5"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 2u32).to_string(),
/// "4/3*x^2-3*x+20"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 100u64).to_string(),
/// "1267650600228229401496703205376/3*x^2-950737950171172051122527404032*x+\
/// 6338253001141147007483516026880"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << 3i8).to_string(),
/// "8/3*x^2-6*x+40"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << -2i16).to_string(),
/// "1/12*x^2-3/16*x+5/4"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() << -100i64).to_string(),
/// "1/3802951800684688204490109616128*x^2-3/5070602400912917605986812821504*x+\
/// 5/1267650600228229401496703205376"
/// );
/// ```
///
/// # shl_assign
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::basic::traits::Zero;
/// use malachite_q::rational_polynomial::RationalPolynomial;
///
/// let mut p = RationalPolynomial::ZERO;
/// p <<= 10u8;
/// assert_eq!(p.to_string(), "0");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p <<= 0u16;
/// assert_eq!(p.to_string(), "1/3*x^2-3/4*x+5");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p <<= 2u32;
/// assert_eq!(p.to_string(), "4/3*x^2-3*x+20");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p <<= 3i8;
/// assert_eq!(p.to_string(), "8/3*x^2-6*x+40");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p <<= -2i16;
/// assert_eq!(p.to_string(), "1/12*x^2-3/16*x+5/4");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p <<= 100u64;
/// assert_eq!(
/// p.to_string(),
/// "1267650600228229401496703205376/3*x^2-950737950171172051122527404032*x+\
/// 6338253001141147007483516026880"
/// );
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p <<= -100i64;
/// assert_eq!(
/// p.to_string(),
/// "1/3802951800684688204490109616128*x^2-3/5070602400912917605986812821504*x+\
/// 5/1267650600228229401496703205376"
/// );
/// ```
/// Right-shifting a [`RationalPolynomial`](super::RationalPolynomial) (dividing it or multiplying
/// it by a power of 2), keeping it in lowest terms.
///
/// # shr
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::basic::traits::Zero;
/// use malachite_q::rational_polynomial::RationalPolynomial;
///
/// assert_eq!((RationalPolynomial::ZERO >> 10u8).to_string(), "0");
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> 0u16).to_string(),
/// "1/3*x^2-3/4*x+5"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> -2i32).to_string(),
/// "4/3*x^2-3*x+20"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> -100i64).to_string(),
/// "1267650600228229401496703205376/3*x^2-950737950171172051122527404032*x+\
/// 6338253001141147007483516026880"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> -3i8).to_string(),
/// "8/3*x^2-6*x+40"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> 2u16).to_string(),
/// "1/12*x^2-3/16*x+5/4"
/// );
/// assert_eq!(
/// (RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> 100u64).to_string(),
/// "1/3802951800684688204490109616128*x^2-3/5070602400912917605986812821504*x+\
/// 5/1267650600228229401496703205376"
/// );
///
/// assert_eq!((&RationalPolynomial::ZERO >> 10u8).to_string(), "0");
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> 0u16).to_string(),
/// "1/3*x^2-3/4*x+5"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> -2i32).to_string(),
/// "4/3*x^2-3*x+20"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> -100i64).to_string(),
/// "1267650600228229401496703205376/3*x^2-950737950171172051122527404032*x+\
/// 6338253001141147007483516026880"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> -3i8).to_string(),
/// "8/3*x^2-6*x+40"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> 2u16).to_string(),
/// "1/12*x^2-3/16*x+5/4"
/// );
/// assert_eq!(
/// (&RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap() >> 100u64).to_string(),
/// "1/3802951800684688204490109616128*x^2-3/5070602400912917605986812821504*x+\
/// 5/1267650600228229401496703205376"
/// );
/// ```
///
/// # shr_assign
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::basic::traits::Zero;
/// use malachite_q::rational_polynomial::RationalPolynomial;
///
/// let mut p = RationalPolynomial::ZERO;
/// p >>= 10u8;
/// assert_eq!(p.to_string(), "0");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p >>= 0u16;
/// assert_eq!(p.to_string(), "1/3*x^2-3/4*x+5");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p >>= -2i32;
/// assert_eq!(p.to_string(), "4/3*x^2-3*x+20");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p >>= -3i8;
/// assert_eq!(p.to_string(), "8/3*x^2-6*x+40");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p >>= 2u16;
/// assert_eq!(p.to_string(), "1/12*x^2-3/16*x+5/4");
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p >>= -100i64;
/// assert_eq!(
/// p.to_string(),
/// "1267650600228229401496703205376/3*x^2-950737950171172051122527404032*x+\
/// 6338253001141147007483516026880"
/// );
///
/// let mut p = RationalPolynomial::from_str("1/3*x^2-3/4*x+5").unwrap();
/// p >>= 100u64;
/// assert_eq!(
/// p.to_string(),
/// "1/3802951800684688204490109616128*x^2-3/5070602400912917605986812821504*x+\
/// 5/1267650600228229401496703205376"
/// );
/// ```
/// Implementations of [`Square`](malachite_base::num::arithmetic::traits::Square) and
/// [`SquareAssign`](malachite_base::num::arithmetic::traits::SquareAssign), for squaring a
/// polynomial.
/// Implementations of [`SquareTruncated`](malachite_base::polynomial::SquareTruncated) and
/// [`SquareTruncatedAssign`](malachite_base::polynomial::SquareTruncatedAssign), for squaring a
/// polynomial and keeping the low coefficients of the square.
/// Implementations of [`Sub`](core::ops::Sub) and [`SubAssign`](core::ops::SubAssign), for
/// subtracting one polynomial from another.
/// Implementations of [`SubTruncated`](malachite_base::polynomial::SubTruncated) and
/// [`SubTruncatedAssign`](malachite_base::polynomial::SubTruncatedAssign), for subtracting one
/// polynomial from another and keeping only their low coefficients.