hacspec_lib/
vec_integers.rs

1#![allow(unused_variables)]
2///!
3///! Implement the `Numeric` trait for arrays.
4///!
5use crate::prelude::*;
6
7#[macro_export]
8#[doc(hidden)]
9macro_rules! _implement_numeric_unsigned_public {
10    ($name:ident) => {
11        impl PartialOrd for $name {
12            #[cfg_attr(feature = "use_attributes", in_hacspec)]
13            fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
14                Some(self.cmp(other))
15            }
16        }
17        impl Ord for $name {
18            #[cfg_attr(feature = "use_attributes", unsafe_hacspec)]
19            fn cmp(&self, other: &Self) -> Ordering {
20                self.0.cmp(&other.0)
21            }
22        }
23        impl Eq for $name {}
24
25        impl $name {
26            /// Check if the two sequences are compatible, i.e. have the same
27            /// length.
28            fn compatible(&self, other: &Self) -> bool {
29                assert!(
30                    self.len() == other.len(),
31                    "Can't combine two sequences that don't have the same length."
32                );
33                if self.len() != other.len() {
34                    return false;
35                }
36                return true;
37            }
38        }
39
40        /// **Warning**: wraps on overflow.
41        impl Add for $name {
42            type Output = $name;
43            #[cfg_attr(feature = "use_attributes", in_hacspec)]
44            fn add(self, rhs: $name) -> $name {
45                self.compatible(&rhs);
46                let mut out = Self::new();
47                for i in 0..self.len() {
48                    out[i] = self[i].wrapping_add(rhs[i])
49                }
50                out
51            }
52        }
53
54        /// **Warning**: wraps on underflow.
55        impl Sub for $name {
56            type Output = $name;
57            #[cfg_attr(feature = "use_attributes", in_hacspec)]
58            fn sub(self, rhs: $name) -> $name {
59                self.compatible(&rhs);
60                let mut out = Self::new();
61                for i in 0..self.len() {
62                    out[i] = self[i].wrapping_sub(rhs[i])
63                }
64                out
65            }
66        }
67
68        /// **Warning**: wraps on overflow.
69        impl Mul for $name {
70            type Output = $name;
71            #[cfg_attr(feature = "use_attributes", in_hacspec)]
72            fn mul(self, rhs: $name) -> $name {
73                self.compatible(&rhs);
74                vec_poly_mul(self, rhs, 0)
75            }
76        }
77
78        /// **Warning**: panics on division by 0.
79        impl Div for $name {
80            type Output = $name;
81            #[cfg_attr(feature = "use_attributes", in_hacspec)]
82            fn div(self, rhs: $name) -> $name {
83                self.compatible(&rhs);
84                let mut out = Self::new();
85                for i in 0..self.len() {
86                    out[i] = self[i].wrapping_div(rhs[i])
87                }
88                out
89            }
90        }
91
92        /// Bit-wise not operation on the coefficients.
93        impl Not for $name {
94            type Output = $name;
95            #[cfg_attr(feature = "use_attributes", in_hacspec)]
96            fn not(self) -> Self::Output {
97                let mut out = Self::new();
98                for i in 0..self.len() {
99                    out[i] = !self[i]
100                }
101                out
102            }
103        }
104
105        /// Bit-wise or operation on the coefficients.
106        impl BitOr for $name {
107            type Output = $name;
108            #[cfg_attr(feature = "use_attributes", in_hacspec)]
109            fn bitor(self, rhs: Self) -> Self::Output {
110                self.compatible(&rhs);
111                let mut out = Self::new();
112                for i in 0..self.len() {
113                    out[i] = self[i] | rhs[i]
114                }
115                out
116            }
117        }
118
119        /// Bit-wise xor operation on the coefficients.
120        impl BitXor for $name {
121            type Output = $name;
122            #[cfg_attr(feature = "use_attributes", in_hacspec)]
123            fn bitxor(self, rhs: Self) -> Self::Output {
124                self.compatible(&rhs);
125                let mut out = Self::new();
126                for i in 0..self.len() {
127                    out[i] = self[i] ^ rhs[i]
128                }
129                out
130            }
131        }
132
133        /// Bit-wise and operation on the coefficients.
134        impl BitAnd for $name {
135            type Output = $name;
136            #[cfg_attr(feature = "use_attributes", in_hacspec)]
137            fn bitand(self, rhs: Self) -> Self::Output {
138                self.compatible(&rhs);
139                let mut out = Self::new();
140                for i in 0..self.len() {
141                    out[i] = self[i] & rhs[i]
142                }
143                out
144            }
145        }
146
147        // TODO: is this a useful thing? Then implement it.
148        /// **Unimplemented**
149        impl Shr<usize> for $name {
150            type Output = $name;
151            #[cfg_attr(feature = "use_attributes", in_hacspec)]
152            fn shr(self, _rhs: usize) -> Self::Output {
153                unimplemented!();
154            }
155        }
156
157        // TODO: is this a useful thing? Then implement it.
158        /// **Unimplemented**
159        impl Shl<usize> for $name {
160            type Output = $name;
161            #[cfg_attr(feature = "use_attributes", in_hacspec)]
162            fn shl(self, _rhs: usize) -> Self::Output {
163                unimplemented!();
164            }
165        }
166
167        impl NumericCopy for $name {}
168        impl ModNumeric for $name {
169            /// `(self - rhs) % n` (coefficient-wise)
170            #[cfg_attr(feature = "use_attributes", in_hacspec)]
171            fn sub_mod(self, rhs: Self, n: Self) -> Self {
172                (self - rhs).modulo(n)
173            }
174            /// `(self + rhs) % n` (coefficient-wise)
175            #[cfg_attr(feature = "use_attributes", in_hacspec)]
176            fn add_mod(self, rhs: Self, n: Self) -> Self {
177                (self + rhs).modulo(n)
178            }
179            /// `(self * rhs) % n` (coefficient-wise)
180            /// Note that the multiplication is wrapping.
181            #[cfg_attr(feature = "use_attributes", in_hacspec)]
182            fn mul_mod(self, rhs: Self, n: Self) -> Self {
183                (self * rhs).modulo(n)
184            }
185            /// `(self ^ exp) % n` (coefficient-wise)
186            /// Note that the exponentiation is wrapping.
187            #[cfg_attr(feature = "use_attributes", in_hacspec)]
188            fn pow_mod(self, exp: Self, n: Self) -> Self {
189                self.pow_self(exp).modulo(n)
190            }
191            /// `self % n` (coefficient-wise)
192            #[cfg_attr(feature = "use_attributes", in_hacspec)]
193            fn modulo(self, n: Self) -> Self {
194                self.compatible(&n);
195                let mut out = Self::new();
196                for i in 0..self.len() {
197                    out[i] = self[i].modulo(n[i])
198                }
199                out
200            }
201            /// `self % n` (coefficient-wise)
202            fn signed_modulo(self, n: Self) -> Self {
203                self.modulo(n)
204            }
205            /// `|self|` (coefficient-wise)
206            #[cfg_attr(feature = "use_attributes", in_hacspec)]
207            fn absolute(self) -> Self {
208                self
209            }
210        }
211        impl Numeric for $name {
212            // TODO: decide if we want this.
213            /// Return largest value that can be represented.
214            /// **Not Implemented**
215            #[cfg_attr(feature = "use_attributes", in_hacspec)]
216            fn max_val() -> Self {
217                unimplemented!();
218            }
219
220            /// `self + rhs` (coefficient-wise and wrapping)
221            #[cfg_attr(feature = "use_attributes", in_hacspec)]
222            fn wrap_add(self, rhs: Self) -> Self {
223                self + rhs
224            }
225
226            /// `self - rhs` (coefficient-wise and wrapping)
227            #[cfg_attr(feature = "use_attributes", in_hacspec)]
228            fn wrap_sub(self, rhs: Self) -> Self {
229                self - rhs
230            }
231
232            /// `self * rhs` (coefficient-wise and wrapping)
233            #[cfg_attr(feature = "use_attributes", in_hacspec)]
234            fn wrap_mul(self, rhs: Self) -> Self {
235                self * rhs
236            }
237
238            /// `self + rhs` (coefficient-wise and wrapping)
239            #[cfg_attr(feature = "use_attributes", in_hacspec)]
240            fn wrap_div(self, rhs: Self) -> Self {
241                // TODO: this won't work vor matrices
242                self / rhs
243            }
244
245            /// `self ^ exp` where `exp` is a `u32` (coefficient-wise and wrapping).
246            #[cfg_attr(feature = "use_attributes", in_hacspec)]
247            fn exp(self, exp: u32) -> Self {
248                let mut out = Self::new();
249                for i in 0..self.len() {
250                    out[i] = self[i].exp(exp)
251                }
252                out
253            }
254
255            /// **Not implemented**.
256            #[cfg_attr(feature = "use_attributes", in_hacspec)]
257            fn pow_self(self, _exp: Self) -> Self {
258                unimplemented!();
259            }
260            /// `self / rhs` (coefficient-wise and wrapping).
261            #[cfg_attr(feature = "use_attributes", in_hacspec)]
262            fn divide(self, rhs: Self) -> Self {
263                self.compatible(&rhs);
264                let mut out = Self::new();
265                for i in 0..self.len() {
266                    out[i] = self[i].div(rhs[i])
267                }
268                out
269            }
270            /// **Not implemented**
271            #[cfg_attr(feature = "use_attributes", in_hacspec)]
272            fn inv(self, _n: Self) -> Self {
273                unimplemented!();
274            }
275
276            // Comparison functions returning bool.
277            #[cfg_attr(feature = "use_attributes", in_hacspec)]
278            fn equal(self, _other: Self) -> bool {
279                unimplemented!();
280            }
281            #[cfg_attr(feature = "use_attributes", in_hacspec)]
282            fn greater_than(self, _other: Self) -> bool {
283                unimplemented!();
284            }
285            #[cfg_attr(feature = "use_attributes", in_hacspec)]
286            fn greater_than_or_equal(self, _other: Self) -> bool {
287                unimplemented!();
288            }
289            #[cfg_attr(feature = "use_attributes", in_hacspec)]
290            fn less_than(self, _other: Self) -> bool {
291                unimplemented!();
292            }
293            #[cfg_attr(feature = "use_attributes", in_hacspec)]
294            fn less_than_or_equal(self, _other: Self) -> bool {
295                unimplemented!();
296            }
297
298            // Comparison functions returning a bit mask (0x0..0 or 0xF..F).
299            #[cfg_attr(feature = "use_attributes", in_hacspec)]
300            fn not_equal_bm(self, _other: Self) -> Self {
301                unimplemented!();
302            }
303            #[cfg_attr(feature = "use_attributes", in_hacspec)]
304            fn equal_bm(self, _other: Self) -> Self {
305                unimplemented!();
306            }
307            #[cfg_attr(feature = "use_attributes", in_hacspec)]
308            fn greater_than_bm(self, _other: Self) -> Self {
309                unimplemented!();
310            }
311            #[cfg_attr(feature = "use_attributes", in_hacspec)]
312            fn greater_than_or_equal_bm(self, _other: Self) -> Self {
313                unimplemented!();
314            }
315            #[cfg_attr(feature = "use_attributes", in_hacspec)]
316            fn less_than_bm(self, _other: Self) -> Self {
317                unimplemented!();
318            }
319            #[cfg_attr(feature = "use_attributes", in_hacspec)]
320            fn less_than_or_equal_bm(self, _other: Self) -> Self {
321                unimplemented!();
322            }
323        }
324    };
325}
326
327#[macro_export]
328#[doc(hidden)]
329macro_rules! _implement_numeric_signed_public {
330    ($name:ident) => {
331        impl PartialOrd for $name {
332            #[cfg_attr(feature = "use_attributes", unsafe_hacspec)]
333            fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
334                Some(self.cmp(other))
335            }
336        }
337        impl Ord for $name {
338            #[cfg_attr(feature = "use_attributes", unsafe_hacspec)]
339            fn cmp(&self, other: &Self) -> Ordering {
340                self.0.cmp(&other.0)
341            }
342        }
343        impl Eq for $name {}
344
345        /// **Warning**: wraps on overflow.
346        impl Add for $name {
347            type Output = $name;
348            #[cfg_attr(feature = "use_attributes", in_hacspec)]
349            fn add(self, rhs: $name) -> $name {
350                unimplemented!();
351            }
352        }
353
354        /// **Warning**: wraps on underflow.
355        impl Sub for $name {
356            type Output = $name;
357            #[cfg_attr(feature = "use_attributes", in_hacspec)]
358            fn sub(self, rhs: $name) -> $name {
359                unimplemented!();
360            }
361        }
362
363        /// **Warning**: wraps on overflow.
364        impl Mul for $name {
365            type Output = $name;
366            #[cfg_attr(feature = "use_attributes", in_hacspec)]
367            fn mul(self, rhs: $name) -> $name {
368                unimplemented!();
369            }
370        }
371
372        /// **Warning**: panics on division by 0.
373        impl Div for $name {
374            type Output = $name;
375            #[cfg_attr(feature = "use_attributes", in_hacspec)]
376            fn div(self, rhs: $name) -> $name {
377                unimplemented!();
378            }
379        }
380
381        /// **Warning**: panics on division by 0.
382        impl Rem for $name {
383            type Output = $name;
384            #[cfg_attr(feature = "use_attributes", in_hacspec)]
385            fn rem(self, rhs: $name) -> $name {
386                unimplemented!();
387            }
388        }
389
390        impl Not for $name {
391            type Output = $name;
392            #[cfg_attr(feature = "use_attributes", in_hacspec)]
393            fn not(self) -> Self::Output {
394                unimplemented!();
395            }
396        }
397
398        impl BitOr for $name {
399            type Output = $name;
400            #[cfg_attr(feature = "use_attributes", in_hacspec)]
401            fn bitor(self, rhs: Self) -> Self::Output {
402                unimplemented!();
403            }
404        }
405
406        impl BitXor for $name {
407            type Output = $name;
408            #[cfg_attr(feature = "use_attributes", in_hacspec)]
409            fn bitxor(self, rhs: Self) -> Self::Output {
410                unimplemented!();
411            }
412        }
413
414        impl BitAnd for $name {
415            type Output = $name;
416            #[cfg_attr(feature = "use_attributes", in_hacspec)]
417            fn bitand(self, rhs: Self) -> Self::Output {
418                unimplemented!();
419            }
420        }
421
422        impl Shr<usize> for $name {
423            type Output = $name;
424            #[cfg_attr(feature = "use_attributes", in_hacspec)]
425            fn shr(self, rhs: usize) -> Self::Output {
426                unimplemented!();
427            }
428        }
429
430        impl Shl<usize> for $name {
431            type Output = $name;
432            #[cfg_attr(feature = "use_attributes", in_hacspec)]
433            fn shl(self, rhs: usize) -> Self::Output {
434                unimplemented!();
435            }
436        }
437
438        impl NumericCopy for $name {}
439        impl ModNumeric for $name {
440            /// (self - rhs) % n.
441            #[cfg_attr(feature = "use_attributes", in_hacspec)]
442            fn sub_mod(self, rhs: Self, n: Self) -> Self {
443                unimplemented!();
444            }
445            /// `(self + rhs) % n`
446            #[cfg_attr(feature = "use_attributes", in_hacspec)]
447            fn add_mod(self, rhs: Self, n: Self) -> Self {
448                unimplemented!();
449            }
450            /// `(self * rhs) % n`
451            #[cfg_attr(feature = "use_attributes", in_hacspec)]
452            fn mul_mod(self, rhs: Self, n: Self) -> Self {
453                unimplemented!();
454            }
455            /// `(self ^ exp) % n`
456            #[cfg_attr(feature = "use_attributes", in_hacspec)]
457            fn pow_mod(self, exp: Self, n: Self) -> Self {
458                unimplemented!();
459            }
460            /// `self % n`
461            #[cfg_attr(feature = "use_attributes", in_hacspec)]
462            fn modulo(self, n: Self) -> Self {
463                unimplemented!();
464            }
465            fn signed_modulo(self, _n: Self) -> Self {
466                unimplemented!();
467            }
468            /// `|self|` (coefficient-wise)
469            #[cfg_attr(feature = "use_attributes", in_hacspec)]
470            fn absolute(self) -> Self {
471                let mut out = Self::new();
472                for i in 0..self.len() {
473                    out[i] = self[i].absolute();
474                }
475                out
476            }
477        }
478        impl Numeric for $name {
479            /// Return largest value that can be represented.
480            #[cfg_attr(feature = "use_attributes", in_hacspec)]
481            fn max_val() -> Self {
482                unimplemented!();
483            }
484
485            #[cfg_attr(feature = "use_attributes", in_hacspec)]
486            fn wrap_add(self, rhs: Self) -> Self {
487                self + rhs
488            }
489
490            #[cfg_attr(feature = "use_attributes", in_hacspec)]
491            fn wrap_sub(self, rhs: Self) -> Self {
492                self - rhs
493            }
494
495            #[cfg_attr(feature = "use_attributes", in_hacspec)]
496            fn wrap_mul(self, rhs: Self) -> Self {
497                self * rhs
498            }
499
500            #[cfg_attr(feature = "use_attributes", in_hacspec)]
501            fn wrap_div(self, rhs: Self) -> Self {
502                unimplemented!();
503            }
504
505            /// `self ^ exp` where `exp` is a `u32`.
506            #[cfg_attr(feature = "use_attributes", in_hacspec)]
507            fn exp(self, exp: u32) -> Self {
508                unimplemented!();
509            }
510            /// `self ^ exp` where `exp` is a `Self`.
511            #[cfg_attr(feature = "use_attributes", in_hacspec)]
512            fn pow_self(self, exp: Self) -> Self {
513                unimplemented!();
514            }
515            /// Division.
516            #[cfg_attr(feature = "use_attributes", in_hacspec)]
517            fn divide(self, rhs: Self) -> Self {
518                unimplemented!();
519            }
520            /// Invert self modulo n.
521            #[cfg_attr(feature = "use_attributes", in_hacspec)]
522            fn inv(self, n: Self) -> Self {
523                unimplemented!();
524            }
525
526            // Comparison functions returning bool.
527            #[cfg_attr(feature = "use_attributes", in_hacspec)]
528            fn equal(self, other: Self) -> bool {
529                unimplemented!();
530            }
531            #[cfg_attr(feature = "use_attributes", in_hacspec)]
532            fn greater_than(self, other: Self) -> bool {
533                unimplemented!();
534            }
535            #[cfg_attr(feature = "use_attributes", in_hacspec)]
536            fn greater_than_or_equal(self, other: Self) -> bool {
537                unimplemented!();
538            }
539            #[cfg_attr(feature = "use_attributes", in_hacspec)]
540            fn less_than(self, other: Self) -> bool {
541                unimplemented!();
542            }
543            #[cfg_attr(feature = "use_attributes", in_hacspec)]
544            fn less_than_or_equal(self, other: Self) -> bool {
545                unimplemented!();
546            }
547
548            // Comparison functions returning a bit mask (0x0..0 or 0xF..F).
549            #[cfg_attr(feature = "use_attributes", in_hacspec)]
550            fn not_equal_bm(self, other: Self) -> Self {
551                unimplemented!();
552            }
553            #[cfg_attr(feature = "use_attributes", in_hacspec)]
554            fn equal_bm(self, other: Self) -> Self {
555                unimplemented!();
556            }
557            #[cfg_attr(feature = "use_attributes", in_hacspec)]
558            fn greater_than_bm(self, other: Self) -> Self {
559                unimplemented!();
560            }
561            #[cfg_attr(feature = "use_attributes", in_hacspec)]
562            fn greater_than_or_equal_bm(self, other: Self) -> Self {
563                unimplemented!();
564            }
565            #[cfg_attr(feature = "use_attributes", in_hacspec)]
566            fn less_than_bm(self, other: Self) -> Self {
567                unimplemented!();
568            }
569            #[cfg_attr(feature = "use_attributes", in_hacspec)]
570            fn less_than_or_equal_bm(self, other: Self) -> Self {
571                unimplemented!();
572            }
573        }
574    };
575}
576
577#[macro_export]
578#[doc(hidden)]
579macro_rules! _implement_numeric_unsigned_secret {
580    ($name:ident, $t:ty) => {
581        /// **Warning**: wraps on overflow.
582        impl Add for $name {
583            type Output = $name;
584            #[cfg_attr(feature = "use_attributes", in_hacspec)]
585            fn add(self, rhs: $name) -> $name {
586                debug_assert!(
587                    self.len() == rhs.len(),
588                    "Can't add two sequences that don't have the same length."
589                );
590                let mut out = Self::new();
591                for i in 0..self.len() {
592                    out[i] = self[i] + rhs[i]
593                }
594                out
595            }
596        }
597
598        /// **Warning**: wraps on underflow.
599        impl Sub for $name {
600            type Output = $name;
601            #[cfg_attr(feature = "use_attributes", in_hacspec)]
602            fn sub(self, rhs: $name) -> $name {
603                debug_assert!(
604                    self.len() == rhs.len(),
605                    "Can't add two sequences that don't have the same length."
606                );
607                let mut out = Self::new();
608                for i in 0..self.len() {
609                    out[i] = self[i] - rhs[i]
610                }
611                out
612            }
613        }
614
615        /// **Warning**: wraps on overflow.
616        impl Mul for $name {
617            type Output = $name;
618            #[cfg_attr(feature = "use_attributes", in_hacspec)]
619            fn mul(self, rhs: $name) -> $name {
620                debug_assert!(
621                    self.len() == rhs.len(),
622                    "Can't add two sequences that don't have the same length."
623                );
624                let mut out = Self::new();
625                for i in 0..self.len() {
626                    out[i] = self[i] * rhs[i]
627                }
628                out
629            }
630        }
631
632        /// **Warning**: panics on division by 0.
633        impl Rem for $name {
634            type Output = $name;
635            #[cfg_attr(feature = "use_attributes", in_hacspec)]
636            fn rem(self, _rhs: $name) -> $name {
637                unimplemented!();
638            }
639        }
640
641        impl Not for $name {
642            type Output = $name;
643            #[cfg_attr(feature = "use_attributes", in_hacspec)]
644            fn not(self) -> Self::Output {
645                unimplemented!();
646            }
647        }
648
649        impl BitOr for $name {
650            type Output = $name;
651            #[cfg_attr(feature = "use_attributes", in_hacspec)]
652            fn bitor(self, _rhs: Self) -> Self::Output {
653                unimplemented!();
654            }
655        }
656
657        impl BitXor for $name {
658            type Output = $name;
659            #[cfg_attr(feature = "use_attributes", in_hacspec)]
660            fn bitxor(self, rhs: Self) -> Self::Output {
661                let mut out = Self::new();
662                for i in 0..self.len() {
663                    out[i] = self[i] ^ rhs[i]
664                }
665                out
666            }
667        }
668
669        impl BitAnd for $name {
670            type Output = $name;
671            #[cfg_attr(feature = "use_attributes", in_hacspec)]
672            fn bitand(self, _rhs: Self) -> Self::Output {
673                unimplemented!();
674            }
675        }
676
677        impl Shr<usize> for $name {
678            type Output = $name;
679            #[cfg_attr(feature = "use_attributes", in_hacspec)]
680            fn shr(self, _rhs: usize) -> Self::Output {
681                unimplemented!();
682            }
683        }
684
685        impl Shl<usize> for $name {
686            type Output = $name;
687            #[cfg_attr(feature = "use_attributes", in_hacspec)]
688            fn shl(self, _rhs: usize) -> Self::Output {
689                unimplemented!();
690            }
691        }
692
693        impl NumericCopy for $name {}
694        impl ModNumeric for $name {
695            /// (self - rhs) % n.
696            #[cfg_attr(feature = "use_attributes", in_hacspec)]
697            fn sub_mod(self, _rhs: Self, _n: Self) -> Self {
698                unimplemented!();
699            }
700            /// `(self + rhs) % n`
701            #[cfg_attr(feature = "use_attributes", in_hacspec)]
702            fn add_mod(self, _rhs: Self, _n: Self) -> Self {
703                unimplemented!();
704            }
705            /// `(self * rhs) % n`
706            #[cfg_attr(feature = "use_attributes", in_hacspec)]
707            fn mul_mod(self, _rhs: Self, _n: Self) -> Self {
708                unimplemented!();
709            }
710            /// `(self ^ exp) % n`
711            #[cfg_attr(feature = "use_attributes", in_hacspec)]
712            fn pow_mod(self, _exp: Self, _n: Self) -> Self {
713                unimplemented!();
714            }
715            /// `self % n`
716            #[cfg_attr(feature = "use_attributes", in_hacspec)]
717            fn modulo(self, _n: Self) -> Self {
718                unimplemented!();
719            }
720            fn signed_modulo(self, _n: Self) -> Self {
721                unimplemented!();
722            }
723            /// `|self|` (coefficient-wise)
724            #[cfg_attr(feature = "use_attributes", in_hacspec)]
725            fn absolute(self) -> Self {
726                self
727            }
728        }
729        impl Numeric for $name {
730            /// Return largest value that can be represented.
731            #[cfg_attr(feature = "use_attributes", in_hacspec)]
732            fn max_val() -> Self {
733                unimplemented!();
734            }
735
736            #[cfg_attr(feature = "use_attributes", in_hacspec)]
737            fn wrap_add(self, rhs: Self) -> Self {
738                self + rhs
739            }
740            #[cfg_attr(feature = "use_attributes", in_hacspec)]
741            fn wrap_sub(self, rhs: Self) -> Self {
742                self - rhs
743            }
744            #[cfg_attr(feature = "use_attributes", in_hacspec)]
745            fn wrap_mul(self, rhs: Self) -> Self {
746                self * rhs
747            }
748            #[cfg_attr(feature = "use_attributes", in_hacspec)]
749            fn wrap_div(self, _rhs: Self) -> Self {
750                unimplemented!();
751            }
752
753            /// `self ^ exp` where `exp` is a `u32`.
754            #[cfg_attr(feature = "use_attributes", in_hacspec)]
755            fn exp(self, _exp: u32) -> Self {
756                unimplemented!();
757            }
758            /// `self ^ exp` where `exp` is a `Self`.
759            #[cfg_attr(feature = "use_attributes", in_hacspec)]
760            fn pow_self(self, _exp: Self) -> Self {
761                unimplemented!();
762            }
763            /// Division.
764            #[cfg_attr(feature = "use_attributes", in_hacspec)]
765            fn divide(self, _rhs: Self) -> Self {
766                unimplemented!();
767            }
768            /// Invert self modulo n.
769            #[cfg_attr(feature = "use_attributes", in_hacspec)]
770            fn inv(self, _n: Self) -> Self {
771                unimplemented!();
772            }
773
774            // Comparison functions returning bool.
775            #[cfg_attr(feature = "use_attributes", in_hacspec)]
776            fn equal(self, other: Self) -> bool {
777                let mut result = <$t>::max_value();
778                for (&a, &b) in self.iter().zip(other.iter()) {
779                    result = result & a.equal_bm(b);
780                }
781                result.declassify() == <$t>::max_value().declassify()
782            }
783            #[cfg_attr(feature = "use_attributes", in_hacspec)]
784            fn greater_than(self, _other: Self) -> bool {
785                unimplemented!();
786            }
787            #[cfg_attr(feature = "use_attributes", in_hacspec)]
788            fn greater_than_or_equal(self, _other: Self) -> bool {
789                unimplemented!();
790            }
791            #[cfg_attr(feature = "use_attributes", in_hacspec)]
792            fn less_than(self, _other: Self) -> bool {
793                unimplemented!();
794            }
795            #[cfg_attr(feature = "use_attributes", in_hacspec)]
796            fn less_than_or_equal(self, _other: Self) -> bool {
797                unimplemented!();
798            }
799
800            // Comparison functions returning a bit mask (0x0..0 or 0xF..F).
801            #[cfg_attr(feature = "use_attributes", in_hacspec)]
802            fn not_equal_bm(self, _other: Self) -> Self {
803                unimplemented!();
804            }
805            #[cfg_attr(feature = "use_attributes", in_hacspec)]
806            fn equal_bm(self, _other: Self) -> Self {
807                unimplemented!();
808            }
809            #[cfg_attr(feature = "use_attributes", in_hacspec)]
810            fn greater_than_bm(self, _other: Self) -> Self {
811                unimplemented!();
812            }
813            #[cfg_attr(feature = "use_attributes", in_hacspec)]
814            fn greater_than_or_equal_bm(self, _other: Self) -> Self {
815                unimplemented!();
816            }
817            #[cfg_attr(feature = "use_attributes", in_hacspec)]
818            fn less_than_bm(self, _other: Self) -> Self {
819                unimplemented!();
820            }
821            #[cfg_attr(feature = "use_attributes", in_hacspec)]
822            fn less_than_or_equal_bm(self, _other: Self) -> Self {
823                unimplemented!();
824            }
825        }
826    };
827}
828
829#[macro_export]
830#[doc(hidden)]
831macro_rules! _implement_numeric_signed_secret {
832    ($name:ident) => {
833        impl PartialOrd for $name {
834            #[cfg_attr(feature = "use_attributes", unsafe_hacspec)]
835            fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
836                Some(self.cmp(other))
837            }
838        }
839        impl Ord for $name {
840            #[cfg_attr(feature = "use_attributes", unsafe_hacspec)]
841            fn cmp(&self, other: &Self) -> Ordering {
842                unimplemented!();
843            }
844        }
845        impl Eq for $name {}
846
847        /// **Warning**: wraps on overflow.
848        impl Add for $name {
849            type Output = $name;
850            #[cfg_attr(feature = "use_attributes", in_hacspec)]
851            fn add(self, rhs: $name) -> $name {
852                unimplemented!();
853            }
854        }
855
856        /// **Warning**: wraps on underflow.
857        impl Sub for $name {
858            type Output = $name;
859            #[cfg_attr(feature = "use_attributes", in_hacspec)]
860            fn sub(self, rhs: $name) -> $name {
861                unimplemented!();
862            }
863        }
864
865        /// **Warning**: wraps on overflow.
866        impl Mul for $name {
867            type Output = $name;
868            #[cfg_attr(feature = "use_attributes", in_hacspec)]
869            fn mul(self, rhs: $name) -> $name {
870                unimplemented!();
871            }
872        }
873
874        /// **Warning**: panics on division by 0.
875        impl Div for $name {
876            type Output = $name;
877            #[cfg_attr(feature = "use_attributes", in_hacspec)]
878            fn div(self, rhs: $name) -> $name {
879                unimplemented!();
880            }
881        }
882
883        /// **Warning**: panics on division by 0.
884        impl Rem for $name {
885            type Output = $name;
886            #[cfg_attr(feature = "use_attributes", in_hacspec)]
887            fn rem(self, rhs: $name) -> $name {
888                unimplemented!();
889            }
890        }
891
892        impl Not for $name {
893            type Output = $name;
894            #[cfg_attr(feature = "use_attributes", in_hacspec)]
895            fn not(self) -> Self::Output {
896                unimplemented!();
897            }
898        }
899
900        impl BitOr for $name {
901            type Output = $name;
902            #[cfg_attr(feature = "use_attributes", in_hacspec)]
903            fn bitor(self, rhs: Self) -> Self::Output {
904                unimplemented!();
905            }
906        }
907
908        impl BitXor for $name {
909            type Output = $name;
910            #[cfg_attr(feature = "use_attributes", in_hacspec)]
911            fn bitxor(self, rhs: Self) -> Self::Output {
912                unimplemented!();
913            }
914        }
915
916        impl BitAnd for $name {
917            type Output = $name;
918            #[cfg_attr(feature = "use_attributes", in_hacspec)]
919            fn bitand(self, rhs: Self) -> Self::Output {
920                unimplemented!();
921            }
922        }
923
924        impl Shr<usize> for $name {
925            type Output = $name;
926            #[cfg_attr(feature = "use_attributes", in_hacspec)]
927            fn shr(self, rhs: usize) -> Self::Output {
928                unimplemented!();
929            }
930        }
931
932        impl Shl<usize> for $name {
933            type Output = $name;
934            #[cfg_attr(feature = "use_attributes", in_hacspec)]
935            fn shl(self, rhs: usize) -> Self::Output {
936                unimplemented!();
937            }
938        }
939
940        impl NumericCopy for $name {}
941        impl ModNumeric for $name {
942            /// (self - rhs) % n.
943            #[cfg_attr(feature = "use_attributes", in_hacspec)]
944            fn sub_mod(self, rhs: Self, n: Self) -> Self {
945                unimplemented!();
946            }
947            /// `(self + rhs) % n`
948            #[cfg_attr(feature = "use_attributes", in_hacspec)]
949            fn add_mod(self, rhs: Self, n: Self) -> Self {
950                unimplemented!();
951            }
952            /// `(self * rhs) % n`
953            #[cfg_attr(feature = "use_attributes", in_hacspec)]
954            fn mul_mod(self, rhs: Self, n: Self) -> Self {
955                unimplemented!();
956            }
957            /// `(self ^ exp) % n`
958            #[cfg_attr(feature = "use_attributes", in_hacspec)]
959            fn pow_mod(self, exp: Self, n: Self) -> Self {
960                unimplemented!();
961            }
962            /// `self % n`
963            #[cfg_attr(feature = "use_attributes", in_hacspec)]
964            fn modulo(self, n: Self) -> Self {
965                unimplemented!();
966            }
967            fn signed_modulo(self, _n: Self) -> Self {
968                unimplemented!();
969            }
970        }
971        impl Numeric for $name {
972            /// Return largest value that can be represented.
973            #[cfg_attr(feature = "use_attributes", in_hacspec)]
974            fn max_val() -> Self {
975                unimplemented!();
976            }
977
978            #[cfg_attr(feature = "use_attributes", in_hacspec)]
979            fn wrap_add(self, rhs: Self) -> Self {
980                self + rhs
981            }
982
983            #[cfg_attr(feature = "use_attributes", in_hacspec)]
984            fn wrap_sub(self, rhs: Self) -> Self {
985                self - rhs
986            }
987
988            #[cfg_attr(feature = "use_attributes", in_hacspec)]
989            fn wrap_mul(self, rhs: Self) -> Self {
990                self * rhs
991            }
992
993            #[cfg_attr(feature = "use_attributes", in_hacspec)]
994            fn wrap_div(self, rhs: Self) -> Self {
995                unimplemented!();
996            }
997
998            /// `self ^ exp` where `exp` is a `u32`.
999            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1000            fn exp(self, exp: u32) -> Self {
1001                unimplemented!();
1002            }
1003            /// `self ^ exp` where `exp` is a `Self`.
1004            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1005            fn pow_self(self, exp: Self) -> Self {
1006                unimplemented!();
1007            }
1008            /// Division.
1009            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1010            fn divide(self, rhs: Self) -> Self {
1011                unimplemented!();
1012            }
1013            /// Invert self modulo n.
1014            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1015            fn inv(self, n: Self) -> Self {
1016                unimplemented!();
1017            }
1018            /// `|self|`
1019            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1020            fn absolute(self) -> Self {
1021                unimplemented!();
1022            }
1023
1024            // Comparison functions returning bool.
1025            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1026            fn equal(self, other: Self) -> bool {
1027                unimplemented!();
1028            }
1029            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1030            fn greater_than(self, other: Self) -> bool {
1031                unimplemented!();
1032            }
1033            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1034            fn greater_than_or_equal(self, other: Self) -> bool {
1035                unimplemented!();
1036            }
1037            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1038            fn less_than(self, other: Self) -> bool {
1039                unimplemented!();
1040            }
1041            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1042            fn less_than_or_equal(self, other: Self) -> bool {
1043                unimplemented!();
1044            }
1045
1046            // Comparison functions returning a bit mask (0x0..0 or 0xF..F).
1047            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1048            fn not_equal_bm(self, other: Self) -> Self {
1049                unimplemented!();
1050            }
1051            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1052            fn equal_bm(self, other: Self) -> Self {
1053                unimplemented!();
1054            }
1055            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1056            fn greater_than_bm(self, other: Self) -> Self {
1057                unimplemented!();
1058            }
1059            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1060            fn greater_than_or_equal_bm(self, other: Self) -> Self {
1061                unimplemented!();
1062            }
1063            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1064            fn less_than_bm(self, other: Self) -> Self {
1065                unimplemented!();
1066            }
1067            #[cfg_attr(feature = "use_attributes", in_hacspec)]
1068            fn less_than_or_equal_bm(self, other: Self) -> Self {
1069                unimplemented!();
1070            }
1071        }
1072    };
1073}
1074
1075#[inline]
1076#[cfg_attr(feature = "use_attributes", in_hacspec)]
1077pub fn vec_poly_mul<T: Numeric + Copy, U: SeqTrait<T>>(x: U, y: U, n: T) -> U {
1078    debug_assert!(x.len() == y.len());
1079    let mut out = U::create(x.len());
1080    for i in 0..x.len() {
1081        if !n.equal(T::default()) {
1082            out[i] = x[i].mul_mod(y[i], n);
1083        } else {
1084            out[i] = x[i].wrap_mul(y[i]);
1085        }
1086    }
1087    out
1088}
1089
1090#[inline]
1091#[cfg_attr(feature = "use_attributes", in_hacspec)]
1092pub fn vec_poly_add<T: Numeric + Copy, U: SeqTrait<T>>(x: U, y: U, n: T) -> U {
1093    debug_assert!(x.len() == y.len());
1094    let mut out = U::create(x.len());
1095    for i in 0..x.len() {
1096        if !n.equal(T::default()) {
1097            out[i] = x[i].add_mod(y[i], n);
1098        } else {
1099            out[i] = x[i].wrap_add(y[i]);
1100        }
1101    }
1102    out
1103}
1104
1105#[inline]
1106#[cfg_attr(feature = "use_attributes", in_hacspec)]
1107pub fn vec_poly_sub<T: Numeric + Copy, U: SeqTrait<T>>(x: U, y: U, n: T) -> U {
1108    debug_assert!(x.len() == y.len());
1109    let mut out = U::create(x.len());
1110    for i in 0..x.len() {
1111        if !n.equal(T::default()) {
1112            out[i] = x[i].sub_mod(y[i], n);
1113        } else {
1114            out[i] = x[i].wrap_sub(y[i]);
1115        }
1116    }
1117    out
1118}
1119
1120// /// Polynomial multiplication on ℤ[x]
1121// impl<T: Numeric> Mul for Seq<T> {
1122//     type Output = Self;
1123//     fn mul(self, rhs: Self) -> Self::Output {
1124//         Self {
1125//             b: poly_mul(&self.b, &rhs.b, T::default()),
1126//             idx: 0,
1127//         }
1128//     }
1129// }
1130
1131// /// Polynomial subtraction on ℤ[x]
1132// impl<T: Numeric> Sub for Seq<T> {
1133//     type Output = Self;
1134//     fn sub(self, rhs: Self) -> Self::Output {
1135//         Self {
1136//             b: vec_poly_sub(&self.b, &rhs.b, T::default()),
1137//             idx: 0,
1138//         }
1139//     }
1140// }
1141
1142// /// Polynomial addition on ℤ[x]
1143// impl<T: Numeric> Add for Seq<T> {
1144//     type Output = Self;
1145//     fn add(self, rhs: Self) -> Self::Output {
1146//         Self {
1147//             b: vec_poly_add(&self.b, &rhs.b, T::default()),
1148//             idx: 0,
1149//         }
1150//     }
1151// }