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
// 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 [`AbsSquared`](malachite_base::num::arithmetic::traits::AbsSquared), the
/// squared norm of a vector: the sum of the squares of its elements.
/// Implementations of [`Add`](core::ops::Add) and [`AddAssign`](core::ops::AddAssign), for adding
/// vectors.
/// Adding a multiple of one vector to another, by implementations of
/// [`AddMul`](malachite_base::num::arithmetic::traits::AddMul) and
/// [`AddMulAssign`](malachite_base::num::arithmetic::traits::AddMulAssign).
///
/// # add_mul
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::arithmetic::traits::AddMul;
/// use malachite_base::num::basic::traits::{NegativeOne, One, Zero};
/// use malachite_q::Rational;
/// use malachite_q::rational_vector::RationalVector;
///
/// assert_eq!(
/// RationalVector::from_str("()")
/// .unwrap()
/// .add_mul(RationalVector::from_str("()").unwrap(), Rational::from(5))
/// .to_string(),
/// "()"
/// );
/// assert_eq!(
/// RationalVector::from_str("(1/2, -2, 3)")
/// .unwrap()
/// .add_mul(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::ZERO
/// )
/// .to_string(),
/// "(1/2, -2, 3)"
/// );
/// assert_eq!(
/// RationalVector::from_str("(1/2, -2, 3)")
/// .unwrap()
/// .add_mul(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::ONE
/// )
/// .to_string(),
/// "(9/2, -5/3, -3)"
/// );
/// assert_eq!(
/// RationalVector::from_str("(1/2, -2, 3)")
/// .unwrap()
/// .add_mul(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::NEGATIVE_ONE
/// )
/// .to_string(),
/// "(-7/2, -7/3, 9)"
/// );
/// assert_eq!(
/// (&RationalVector::from_str("(1/2, -2, 3)").unwrap())
/// .add_mul(
/// &RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// &Rational::from_signeds(3, 2)
/// )
/// .to_string(),
/// "(13/2, -3/2, -6)"
/// );
/// ```
///
/// # add_mul_assign
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::arithmetic::traits::AddMulAssign;
/// use malachite_q::Rational;
/// use malachite_q::rational_vector::RationalVector;
///
/// let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
/// v.add_mul_assign(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::from_signeds(3, 2),
/// );
/// assert_eq!(v.to_string(), "(13/2, -3/2, -6)");
/// ```
/// Implementations of [`AddMulShl`](malachite_base::num::arithmetic::traits::AddMulShl) and
/// [`AddMulShlAssign`](malachite_base::num::arithmetic::traits::AddMulShlAssign), for adding a
/// scalar multiple of one vector, shifted left, to another.
/// Implementations of [`CanonicalPrimitivePart`](
/// malachite_base::num::arithmetic::traits::CanonicalPrimitivePart) and
/// [`ContentAndCanonicalPrimitivePart`](
/// malachite_base::num::arithmetic::traits::ContentAndCanonicalPrimitivePart), which compute the
/// primitive part of a vector with its first nonzero element made positive.
/// Implementations of
/// [`CanonicalizeSign`](malachite_base::num::arithmetic::traits::CanonicalizeSign) and
/// [`CanonicalizeSignAssign`](malachite_base::num::arithmetic::traits::CanonicalizeSignAssign),
/// which negate a vector if its pivot is negative.
/// Implementations of [`Content`](malachite_base::num::arithmetic::traits::Content),
/// [`PrimitivePart`](malachite_base::num::arithmetic::traits::PrimitivePart), and
/// [`ContentAndPrimitivePart`](malachite_base::num::arithmetic::traits::ContentAndPrimitivePart),
/// which split a vector into a rational scalar and a vector of coprime integers.
/// Implementations of [`ContentChained`](malachite_base::num::arithmetic::traits::ContentChained),
/// which computes the GCD of a number and a vector's elements.
/// Implementations of [`Dot`](malachite_base::num::arithmetic::traits::Dot), the dot product of two
/// vectors.
/// Implementations of [`DotSign`](malachite_base::num::arithmetic::traits::DotSign), the sign of
/// the dot product of two vectors.
/// An implementation of
/// [`ElementProduct`](malachite_base::num::arithmetic::traits::ElementProduct), the product of the
/// elements.
/// An implementation of [`ElementSum`](malachite_base::num::arithmetic::traits::ElementSum), the
/// sum of the elements.
/// Implementations of [`EntrywiseAbs`](malachite_base::num::arithmetic::traits::EntrywiseAbs) and
/// [`EntrywiseAbsAssign`](malachite_base::num::arithmetic::traits::EntrywiseAbsAssign), which
/// replace every element of a vector by its absolute value.
/// An implementation of [`Height`](malachite_base::num::arithmetic::traits::Height) and
/// [`HeightRef`](malachite_base::num::arithmetic::traits::HeightRef), the largest height of any
/// element.
/// An implementation of [`L1Norm`](malachite_base::num::arithmetic::traits::L1Norm), the sum of the
/// absolute values of the elements.
/// Implementations of [`Neg`](core::ops::Neg) and
/// [`NegAssign`](malachite_base::num::arithmetic::traits::NegAssign), for negating a vector.
/// Implementations of [`Div`](core::ops::Div) and [`DivAssign`](core::ops::DivAssign), for dividing
/// a vector by a scalar.
/// Implementations of [`Mul`](core::ops::Mul) and [`MulAssign`](core::ops::MulAssign), for
/// multiplying a vector by a scalar, with the scalar on either side.
/// Left-shifting a vector (multiplying it by a power of 2), by implementations of
/// [`Shl`](core::ops::Shl) and [`ShlAssign`](core::ops::ShlAssign).
///
/// # shl
/// ```
/// use core::str::FromStr;
/// use malachite_q::rational_vector::RationalVector;
///
/// assert_eq!(
/// (RationalVector::from_str("()").unwrap() << 10u8).to_string(),
/// "()"
/// );
/// assert_eq!(
/// (RationalVector::from_str("(1/2, -3/4, 3)").unwrap() << 0u16).to_string(),
/// "(1/2, -3/4, 3)"
/// );
/// assert_eq!(
/// (RationalVector::from_str("(1/2, -3/4, 3)").unwrap() << 2u32).to_string(),
/// "(2, -3, 12)"
/// );
/// assert_eq!(
/// (&RationalVector::from_str("(1/8, 0)").unwrap() << 100u64).to_string(),
/// "(158456325028528675187087900672, 0)"
/// );
///
/// assert_eq!(
/// (RationalVector::from_str("(1/2, -3/4, 3)").unwrap() << 2i8).to_string(),
/// "(2, -3, 12)"
/// );
/// assert_eq!(
/// (&RationalVector::from_str("(1/2, -3/4, 3)").unwrap() << -2i64).to_string(),
/// "(1/8, -3/16, 3/4)"
/// );
/// ```
///
/// # shl_assign
/// ```
/// use core::str::FromStr;
/// use malachite_q::rational_vector::RationalVector;
///
/// let mut v = RationalVector::from_str("(1/2, -3/4, 3)").unwrap();
/// v <<= 2u32;
/// assert_eq!(v.to_string(), "(2, -3, 12)");
///
/// let mut v = RationalVector::from_str("(1/2, -3/4, 3)").unwrap();
/// v <<= -2i32;
/// assert_eq!(v.to_string(), "(1/8, -3/16, 3/4)");
/// ```
/// Right-shifting a vector (dividing it by a power of 2), by implementations of
/// [`Shr`](core::ops::Shr) and [`ShrAssign`](core::ops::ShrAssign).
///
/// # shr
/// ```
/// use core::str::FromStr;
/// use malachite_q::rational_vector::RationalVector;
///
/// assert_eq!(
/// (RationalVector::from_str("()").unwrap() >> 10u8).to_string(),
/// "()"
/// );
/// assert_eq!(
/// (RationalVector::from_str("(1/2, -3/4, 3)").unwrap() >> 0u16).to_string(),
/// "(1/2, -3/4, 3)"
/// );
/// assert_eq!(
/// (RationalVector::from_str("(1/2, -3/4, 3)").unwrap() >> 2u32).to_string(),
/// "(1/8, -3/16, 3/4)"
/// );
/// assert_eq!(
/// (&RationalVector::from_str("(12, 0)").unwrap() >> 100u64).to_string(),
/// "(3/316912650057057350374175801344, 0)"
/// );
///
/// assert_eq!(
/// (RationalVector::from_str("(1/2, -3/4, 3)").unwrap() >> 2i8).to_string(),
/// "(1/8, -3/16, 3/4)"
/// );
/// assert_eq!(
/// (&RationalVector::from_str("(1/2, -3/4, 3)").unwrap() >> -2i64).to_string(),
/// "(2, -3, 12)"
/// );
/// ```
///
/// # shr_assign
/// ```
/// use core::str::FromStr;
/// use malachite_q::rational_vector::RationalVector;
///
/// let mut v = RationalVector::from_str("(1/2, -3/4, 3)").unwrap();
/// v >>= 2u32;
/// assert_eq!(v.to_string(), "(1/8, -3/16, 3/4)");
///
/// let mut v = RationalVector::from_str("(1/2, -3/4, 3)").unwrap();
/// v >>= -2i32;
/// assert_eq!(v.to_string(), "(2, -3, 12)");
/// ```
/// Implementations of [`Sub`](core::ops::Sub) and [`SubAssign`](core::ops::SubAssign), for
/// subtracting vectors.
/// Subtracting a multiple of one vector from another, by implementations of
/// [`SubMul`](malachite_base::num::arithmetic::traits::SubMul) and
/// [`SubMulAssign`](malachite_base::num::arithmetic::traits::SubMulAssign).
///
/// # sub_mul
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::arithmetic::traits::SubMul;
/// use malachite_base::num::basic::traits::{NegativeOne, One, Zero};
/// use malachite_q::Rational;
/// use malachite_q::rational_vector::RationalVector;
///
/// assert_eq!(
/// RationalVector::from_str("()")
/// .unwrap()
/// .sub_mul(RationalVector::from_str("()").unwrap(), Rational::from(5))
/// .to_string(),
/// "()"
/// );
/// assert_eq!(
/// RationalVector::from_str("(1/2, -2, 3)")
/// .unwrap()
/// .sub_mul(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::ZERO
/// )
/// .to_string(),
/// "(1/2, -2, 3)"
/// );
/// assert_eq!(
/// RationalVector::from_str("(1/2, -2, 3)")
/// .unwrap()
/// .sub_mul(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::ONE
/// )
/// .to_string(),
/// "(-7/2, -7/3, 9)"
/// );
/// assert_eq!(
/// RationalVector::from_str("(1/2, -2, 3)")
/// .unwrap()
/// .sub_mul(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::NEGATIVE_ONE
/// )
/// .to_string(),
/// "(9/2, -5/3, -3)"
/// );
/// assert_eq!(
/// (&RationalVector::from_str("(1/2, -2, 3)").unwrap())
/// .sub_mul(
/// &RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// &Rational::from_signeds(3, 2)
/// )
/// .to_string(),
/// "(-11/2, -5/2, 12)"
/// );
/// ```
///
/// # sub_mul_assign
/// ```
/// use core::str::FromStr;
/// use malachite_base::num::arithmetic::traits::SubMulAssign;
/// use malachite_q::Rational;
/// use malachite_q::rational_vector::RationalVector;
///
/// let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
/// v.sub_mul_assign(
/// RationalVector::from_str("(4, 1/3, -6)").unwrap(),
/// Rational::from_signeds(3, 2),
/// );
/// assert_eq!(v.to_string(), "(-11/2, -5/2, 12)");
/// ```
/// Implementations of [`SubMulShl`](malachite_base::num::arithmetic::traits::SubMulShl) and
/// [`SubMulShlAssign`](malachite_base::num::arithmetic::traits::SubMulShlAssign), for subtracting a
/// scalar multiple of one vector, shifted left, from another.
/// Implementations of [`Sum`](core::iter::Sum), for adding up vectors entry by entry.