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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
// Copyright © 2023 Marcel Luca Schmidt, Marvin Beckmann
//
// This file is part of qFALL-math.
//
// qFALL-math is free software: you can redistribute it and/or modify it under
// the terms of the Mozilla Public License Version 2.0 as published by the
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
//! Implementations to create a [`PolynomialRingZq`] value from other types.
//!
//! The explicit functions contain the documentation.
use super::PolynomialRingZq;
use crate::{
error::{MathError, StringConversionError},
integer::PolyOverZ,
integer_mod_q::{ModulusPolynomialRingZq, NTTPolynomialRingZq, PolyOverZq},
macros::for_others::implement_for_owned,
};
use std::str::FromStr;
impl From<NTTPolynomialRingZq> for PolynomialRingZq {
/// Creates a polynomial from [`NTTPolynomialRingZq`] generated with respect to the
/// [`NTTBasisPolynomialRingZq`](crate::integer_mod_q::NTTBasisPolynomialRingZq) as part of
/// [`ModulusPolynomialRingZq`].
///
/// Parameters:
/// - `ntt`: the NTT representation of the polynomial.
/// - `modulus`: the modulus that is applied to the polynomial ring element.
///
/// Returns a new [`PolynomialRingZq`] with the specified [`ModulusPolynomialRingZq`] and
/// values as defined in `ntt`.
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::{PolynomialRingZq, PolyOverZq, ModulusPolynomialRingZq, NTTPolynomialRingZq};
/// use qfall_math::traits::SetCoefficient;
///
/// let n = 4;
/// let modulus = 7681;
///
/// let mut mod_poly = PolyOverZq::from(modulus);
/// mod_poly.set_coeff(0, 1).unwrap();
/// mod_poly.set_coeff(n, 1).unwrap();
///
/// let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
/// polynomial_modulus.set_ntt_unchecked(1925);
///
/// let ntt = NTTPolynomialRingZq::sample_uniform(&polynomial_modulus);
///
/// let res = PolynomialRingZq::from(ntt);
/// ```
///
/// # Panics ...
/// - if the [`NTTBasisPolynomialRingZq`](crate::integer_mod_q::NTTBasisPolynomialRingZq) in `modulus`
/// is not set.
fn from(ntt: NTTPolynomialRingZq) -> Self {
ntt.inv_ntt()
}
}
impl From<&ModulusPolynomialRingZq> for PolynomialRingZq {
/// Creates a zero polynomial with a given [`ModulusPolynomialRingZq`].
///
/// Parameters:
/// - `modulus`: the modulus that is applied to the polynomial ring element.
///
/// Returns a new constant [`PolynomialRingZq`] with the specified [`ModulusPolynomialRingZq`].
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::PolynomialRingZq;
/// use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
/// use qfall_math::integer_mod_q::PolyOverZq;
/// use std::str::FromStr;
///
/// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
/// let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
/// let poly_ring = PolynomialRingZq::from((poly, &modulus));
/// ```
///
/// # Panics ...
/// - if the moduli mismatch.
fn from(modulus: &ModulusPolynomialRingZq) -> Self {
let modulus = modulus.into();
Self {
poly: PolyOverZ::default(),
modulus,
}
}
}
implement_for_owned!(ModulusPolynomialRingZq, PolynomialRingZq, From);
impl<Poly: Into<PolyOverZ>, Mod: Into<ModulusPolynomialRingZq>> From<(Poly, Mod)>
for PolynomialRingZq
{
/// Creates a new polynomial ring element of type [`PolynomialRingZq`].
///
/// Parameters:
/// - `poly`: the coefficients of the polynomial.
/// - `modulus`: the modulus that is applied to the polynomial ring element.
///
/// Returns a new element inside the polynomial ring.
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::PolynomialRingZq;
/// use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
/// use qfall_math::integer::PolyOverZ;
/// use std::str::FromStr;
///
/// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
/// let poly = PolyOverZ::from_str("4 -1 0 1 1").unwrap();
/// let poly_ring = PolynomialRingZq::from((&poly, &modulus));
/// ```
fn from((poly, modulus): (Poly, Mod)) -> Self {
let mut out = Self {
poly: poly.into(),
modulus: modulus.into(),
};
out.reduce();
out
}
}
impl<Mod: Into<ModulusPolynomialRingZq>> From<(&PolyOverZq, Mod)> for PolynomialRingZq {
/// Creates a new polynomial ring element of type [`PolynomialRingZq`].
///
/// Parameters:
/// - `poly`: the coefficients of the polynomial.
/// - `modulus`: the modulus that is applied to the polynomial ring element.
///
/// Returns a new element inside the polynomial ring, if the moduli of the
/// polynomial and the modulus match.
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::PolynomialRingZq;
/// use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
/// use qfall_math::integer_mod_q::PolyOverZq;
/// use std::str::FromStr;
///
/// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
/// let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
/// let poly_ring = PolynomialRingZq::from((&poly, &modulus));
/// ```
///
/// # Panics ...
/// - if the moduli mismatch.
fn from((poly, modulus): (&PolyOverZq, Mod)) -> Self {
let modulus = modulus.into();
assert_eq!(
poly.modulus,
modulus.get_q(),
"The moduli of the polynomial and the modulus mismatch."
);
let mut out = Self {
poly: poly.get_representative_least_nonnegative_residue(),
modulus,
};
out.reduce();
out
}
}
impl<Mod: Into<ModulusPolynomialRingZq>> From<(PolyOverZq, Mod)> for PolynomialRingZq {
/// Creates a new polynomial ring element of type [`PolynomialRingZq`].
///
/// Parameters:
/// - `poly`: the coefficients of the polynomial.
/// - `modulus`: the modulus that is applied to the polynomial ring element.
///
/// Returns a new element inside the polynomial ring, if the moduli of the
/// polynomial and the modulus match.
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::PolynomialRingZq;
/// use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
/// use qfall_math::integer_mod_q::PolyOverZq;
/// use std::str::FromStr;
///
/// let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
/// let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 17").unwrap();
/// let poly_ring = PolynomialRingZq::from((poly, &modulus));
/// ```
///
/// # Panics ...
/// - if the moduli mismatch.
fn from((poly, modulus): (PolyOverZq, Mod)) -> Self {
let modulus = modulus.into();
assert_eq!(
poly.modulus,
modulus.get_q(),
"The moduli of the polynomial and the modulus mismatch."
);
let mut out = Self {
poly: poly.get_representative_least_nonnegative_residue(),
modulus,
};
out.reduce();
out
}
}
impl FromStr for PolynomialRingZq {
type Err = MathError;
/// Creates a polynomial ring element of type [`PolynomialRingZq`].
///
/// **Warning**: If the polynomials start with a correctly formatted
/// [`PolyOverZ`] object, the rest of the string
/// until the `"/"` (for the first polynomial) or `"mod"` (for the second polynomial)
/// is ignored. This means that the input string `"4 0 1 2 3 / 2 1 1 mod 13"`
/// is the same as `"4 0 1 2 3 4 5 6 7 / 2 1 1 mod 13"`.
///
/// Parameters:
/// - `s`: the polynomial ring element of form:
/// `"[#number of coefficients of element]⌴⌴[0th coefficient]⌴
/// [1st coefficient]⌴...⌴/⌴[#number of coefficients of polynomial modulus]⌴⌴
/// [0th coefficient]⌴[1st coefficient]⌴...⌴mod⌴[q]"`.
///
/// Note that the `[#number of coefficients]` and `[0th coefficient]`
/// are divided by two spaces and the strings for the polynomials are trimmed,
/// i.e. all whitespaces around the polynomials and the modulus are ignored.
///
/// Returns a [`PolynomialRingZq`] or an error if the provided string was not
/// formatted correctly, the numbers of coefficients were smaller than the numbers
/// provided at the start of the provided string, or the modulus was smaller than `2`.
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::PolynomialRingZq;
/// use std::str::FromStr;
///
/// let poly = PolynomialRingZq::from_str("4 -1 0 1 1 / 4 0 1 -2 1 mod 42").unwrap();
/// ```
/// # Errors and Failures
/// - Returns a [`MathError`] of type
/// [`StringConversionError`](MathError::StringConversionError)
/// - if the provided first half of the string was not formatted correctly to
/// create a [`PolyOverZ`],
/// - if the provided second half of the
/// string was not formatted correctly to create a [`ModulusPolynomialRingZq`],
/// - if the numbers of coefficients were smaller than the numbers provided
/// at the start of the provided string,
/// - if the provided values did not contain two whitespaces, or
/// - if the delimiter `/` and `mod` could not be found.
/// - Returns a [`MathError`] of type
/// [`InvalidModulus`](MathError::InvalidModulus)
/// if the integer modulus `q` is smaller than `2`.
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (poly_s, modulus) = match s.split_once("/") {
Some((poly_s, modulus)) => (poly_s, modulus),
None => {
return Err(StringConversionError::InvalidStringToPolyRingZqInput(
s.to_owned(),
))?;
}
};
let poly_over_z = PolyOverZ::from_str(poly_s)?;
let modulus = ModulusPolynomialRingZq::from_str(modulus)?;
Ok(Self::from((&poly_over_z, &modulus)))
}
}
#[cfg(test)]
mod test_from_ntt_modulus_polynomial_ring_zq {
use crate::{
integer::{PolyOverZ, Z},
integer_mod_q::{ModulusPolynomialRingZq, NTTPolynomialRingZq, PolynomialRingZq},
};
use std::str::FromStr;
/// Ensures that `inv_ntt` works properly and that we can make a round trip and get to the same ntt representation.
#[test]
fn round_trip() {
let mut mod_poly = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
mod_poly.set_ntt_unchecked(64);
let poly = PolyOverZ::from_str("4 103 182 146 116").unwrap();
let poly_ring_zq = PolynomialRingZq::from((poly, &mod_poly));
let cmp_ntt = NTTPolynomialRingZq {
poly: vec![Z::from(113), Z::from(54), Z::from(47), Z::from(198)],
modulus: mod_poly.clone(),
};
let ntt = NTTPolynomialRingZq::from(&poly_ring_zq);
assert_eq!(ntt, cmp_ntt);
let res_poly_ring_zq = PolynomialRingZq::from(ntt);
assert_eq!(res_poly_ring_zq, poly_ring_zq);
}
}
#[cfg(test)]
mod test_from_modulus_polynomial_ring_zq {
use crate::{
integer::PolyOverZ,
integer_mod_q::{ModulusPolynomialRingZq, PolynomialRingZq},
};
use std::str::FromStr;
/// Ensure that the default value is set correctly and that the modulus is correct
#[test]
fn is_reduced_large() {
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly_ring = PolynomialRingZq::from(&modulus);
assert_eq!(PolyOverZ::default(), poly_ring.poly);
assert_eq!(modulus, poly_ring.modulus);
}
/// Ensures that the function is still available for all values implementing
/// `Into<ModulusPolynomialRingZq>`.
#[test]
fn availability() {
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let _ = PolynomialRingZq::from(&modulus);
let _ = PolynomialRingZq::from(modulus);
}
}
#[cfg(test)]
mod test_from_poly_over_z_modulus_polynomial_ring_zq {
use crate::{
integer::{PolyOverZ, Z},
integer_mod_q::{Modulus, ModulusPolynomialRingZq, PolyOverZq, PolynomialRingZq},
};
use std::str::FromStr;
const LARGE_PRIME: u64 = u64::MAX - 58;
/// Ensure that the modulus is applied with a large prime and large coefficients
#[test]
fn is_reduced_large() {
let modulus =
ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {LARGE_PRIME}")).unwrap();
let poly =
PolyOverZ::from_str(&format!("4 {} {} 1 1", LARGE_PRIME + 2, u64::MAX)).unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let cmp_poly = PolyOverZ::from_str("3 1 58 1").unwrap();
let cmp_poly_ring = PolynomialRingZq::from((&cmp_poly, &modulus));
assert_eq!(poly_ring, cmp_poly_ring);
}
/// Ensure that two ring elements that are instantiated the same way are equal
#[test]
fn same_instantiation() {
let modulus =
ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {LARGE_PRIME}")).unwrap();
let poly =
PolyOverZ::from_str(&format!("4 {} {} 1 1", LARGE_PRIME + 2, u64::MAX)).unwrap();
let poly_ring_1 = PolynomialRingZq::from((&poly, &modulus));
let poly_ring_2 = PolynomialRingZq::from((&poly, &modulus));
assert_eq!(poly_ring_1, poly_ring_2);
}
/// Ensures that the function is still available for all values implementing
/// `Into<ModulusPolynomialRingZq>`.
#[test]
fn availability() {
let z = Z::from(2);
let q = Modulus::from(17);
let poly = PolyOverZ::from(2);
let poly_mod = PolyOverZq::from_str("2 1 1 mod 17").unwrap();
let modulus = ModulusPolynomialRingZq::from(&poly_mod);
let _ = PolynomialRingZq::from((&poly, &poly_mod));
let _ = PolynomialRingZq::from((&poly, poly_mod.clone()));
let _ = PolynomialRingZq::from((poly.clone(), &poly_mod));
let _ = PolynomialRingZq::from((poly.clone(), poly_mod));
let _ = PolynomialRingZq::from((0_i8, &modulus));
let _ = PolynomialRingZq::from((0_i16, &modulus));
let _ = PolynomialRingZq::from((0_i32, &modulus));
let _ = PolynomialRingZq::from((0_i64, &modulus));
let _ = PolynomialRingZq::from((0_u8, &modulus));
let _ = PolynomialRingZq::from((0_u16, &modulus));
let _ = PolynomialRingZq::from((0_u32, &modulus));
let _ = PolynomialRingZq::from((0_u64, &modulus));
let _ = PolynomialRingZq::from((&z, &modulus));
let _ = PolynomialRingZq::from((z, &modulus));
let _ = PolynomialRingZq::from((&q, &modulus));
let _ = PolynomialRingZq::from((q, &modulus));
let _ = PolynomialRingZq::from((poly.clone(), &modulus));
let _ = PolynomialRingZq::from((poly, modulus));
}
}
#[cfg(test)]
mod test_from_poly_over_zq_modulus_polynomial_ring_zq {
use crate::{
integer::PolyOverZ,
integer_mod_q::{ModulusPolynomialRingZq, PolyOverZq, PolynomialRingZq},
};
use std::str::FromStr;
const LARGE_PRIME: u64 = u64::MAX - 58;
/// Ensure that the modulus is applied with a large prime and large coefficients
#[test]
fn is_reduced_large() {
let modulus =
ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {LARGE_PRIME}")).unwrap();
let poly = PolyOverZq::from_str(&format!(
"4 {} {} 1 1 mod {}",
LARGE_PRIME + 2,
u64::MAX,
LARGE_PRIME
))
.unwrap();
let poly_ring = PolynomialRingZq::from((&poly, &modulus));
let cmp_poly = PolyOverZ::from_str("3 1 58 1").unwrap();
let cmp_poly_ring = PolynomialRingZq::from((&cmp_poly, &modulus));
assert_eq!(poly_ring, cmp_poly_ring);
}
/// Ensure that two ring elements that are instantiated the same way are equal
#[test]
fn same_instantiation() {
let modulus =
ModulusPolynomialRingZq::from_str(&format!("4 1 0 0 1 mod {LARGE_PRIME}")).unwrap();
let poly = PolyOverZq::from_str(&format!(
"4 {} {} 1 1 mod {}",
LARGE_PRIME + 2,
u64::MAX,
LARGE_PRIME
))
.unwrap();
let poly_ring_1 = PolynomialRingZq::from((&poly, &modulus));
let poly_ring_2 = PolynomialRingZq::from((&poly, &modulus));
assert_eq!(poly_ring_1, poly_ring_2);
}
/// Ensures that the function is still available for all values implementing
/// `Into<ModulusPolynomialRingZq>`.
#[test]
fn availability() {
let poly_mod = PolyOverZq::from_str("2 1 1 mod 17").unwrap();
let modulus = ModulusPolynomialRingZq::from(&poly_mod);
let _ = PolynomialRingZq::from((&poly_mod, &poly_mod));
let _ = PolynomialRingZq::from((&poly_mod, poly_mod.clone()));
let _ = PolynomialRingZq::from((poly_mod.clone(), &poly_mod));
let _ = PolynomialRingZq::from((poly_mod.clone(), poly_mod.clone()));
let _ = PolynomialRingZq::from((&poly_mod, &modulus));
let _ = PolynomialRingZq::from((&poly_mod, modulus.clone()));
let _ = PolynomialRingZq::from((poly_mod.clone(), &modulus));
let _ = PolynomialRingZq::from((poly_mod, modulus));
}
/// Ensure that the function panics if the moduli mismatch.
#[test]
#[should_panic]
fn mismatiching_modulus_error_borrowed() {
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 13").unwrap();
let _ = PolynomialRingZq::from((&poly, &modulus));
}
/// Ensure that the function panics if the moduli mismatch.
#[test]
#[should_panic]
fn mismatiching_modulus_error_owned() {
let modulus = ModulusPolynomialRingZq::from_str("4 1 0 0 1 mod 17").unwrap();
let poly = PolyOverZq::from_str("4 -1 0 1 1 mod 13").unwrap();
let _ = PolynomialRingZq::from((poly, &modulus));
}
}
#[cfg(test)]
mod test_from_str {
use super::PolynomialRingZq;
use std::str::FromStr;
/// tests whether a falsely formatted string (integer modulus is 0) returns an
/// error
#[test]
fn modulus_zero_throws_error() {
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / 4 0 1 -2 1 mod 0").is_err());
}
/// tests whether a false string (negative modulus) returns an error
#[test]
fn false_sign() {
assert!(PolynomialRingZq::from_str("4 0 1 -2 1 mod -42").is_err());
}
/// tests whether a falsely formatted string (wrong whitespaces) returns an
/// error
#[test]
fn whitespaces_in_modulus() {
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / 4 0 1 -2 1 mod 4 2").is_err());
}
/// tests whether a falsely formatted string (wrong symbols) returns an error
#[test]
fn false_format_symbols() {
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / 1 1 mod ba").is_err());
assert!(PolynomialRingZq::from_str("4 -1 0 1a 1 / 1 1 mod 42").is_err());
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / b 1 mod 42").is_err());
}
/// tests whether a falsely formatted string (missing double-space) returns
/// an error
#[test]
fn false_format() {
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / 4 0 1 -2 1 mod 42").is_err());
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / 4 0 1 -2 1 mod 42").is_err());
}
/// tests whether a falsely formatted string (wrong number of total
/// coefficients) returns an error
#[test]
fn false_number_of_coefficient() {
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / 5 0 1 -2 1 mod 42").is_err());
assert!(PolynomialRingZq::from_str("5 -1 0 1 1 / 4 0 1 -2 1 mod 42").is_err());
}
/// tests whether a falsely formatted string (too many whitespaces) returns
/// an error
#[test]
fn too_many_whitespaces() {
assert!(PolynomialRingZq::from_str("4 -1 0 1 1 / 4 0 1 -2 1 mod 42").is_err());
}
/// Ensure that the input works with strings that have to be trimmed
#[test]
fn trim_input() {
let poly = PolynomialRingZq::from_str(
" 4 -1 0 1 1 / 4 1 2 3 1 mod 17 ",
);
assert!(poly.is_ok());
assert_eq!(
PolynomialRingZq::from_str("4 -1 0 1 1 / 4 1 2 3 1 mod 17").unwrap(),
poly.unwrap()
);
}
/// Ensure that a string resulting from to_string, can be used in from_str
#[test]
fn roundtrip() {
let poly = PolynomialRingZq::from_str("2 1 1 / 4 1 1 -2 1 mod 42").unwrap();
let poly2 = PolynomialRingZq::from_str(&poly.to_string()).unwrap();
assert_eq!(poly, poly2);
}
}