@@ -44,11 +44,11 @@ impl<CapacityUsed: Unsigned> LazyField<CapacityUsed> for FieldElement<CapacityUs
4444 > (
4545 self ,
4646 other : & T ,
47- ) -> impl Reducible < Output = <Self as Reducible >:: Output >
48- + LazyField <
47+ ) -> impl LazyField <
4948 <V as Add < CapacityUsed > >:: Output ,
5049 Capacity = Self :: Capacity ,
5150 Underlying = Self :: Underlying ,
51+ Output = <Self as Reducible >:: Output ,
5252 > {
5353 FieldElement :: < <V as Add < CapacityUsed > >:: Output > :: from ( & self . 0 . 0 + & other. as_underlying ( ) . 0 )
5454 }
@@ -64,16 +64,34 @@ impl<CapacityUsed: Unsigned> LazyField<CapacityUsed> for FieldElement<CapacityUs
6464
6565#[ cfg( test) ]
6666mod tests {
67- use rand_core:: { OsRng , TryRngCore } ;
68- use typenum:: U3 ;
69-
7067 use crate :: hazmat:: lazy_field:: { EagerField , LazyField , LazyFieldWithCapacity , Reducible } ;
68+ use typenum:: { B1 , U2 , U3 , type_operators:: IsLessOrEqual } ;
69+
70+ fn add_triple_then_mul < F : LazyFieldWithCapacity < U3 > > (
71+ a : F ,
72+ b : F ,
73+ c : F ,
74+ d : F ,
75+ e : F ,
76+ f : F ,
77+ ) -> <F as Reducible >:: Output
78+ where
79+ U2 : IsLessOrEqual < F :: Capacity , Output = B1 > ,
80+ U3 : IsLessOrEqual < F :: Capacity , Output = B1 > ,
81+ {
82+ let ab = a. add ( & b) ;
83+ let abc = ab. add ( & c) ;
84+ let de = d. add ( & e) ;
85+ let def = de. add ( & f) ;
86+ abc. mul ( & def)
87+ }
7188
7289 #[ test]
7390 fn lazy_add_then_mul ( ) {
7491 use crate :: hazmat:: FieldElement ;
7592 use core:: marker:: PhantomData ;
7693 use ff:: Field ;
94+ use rand_core:: { OsRng , TryRngCore } ;
7795
7896 let mut rng = OsRng . unwrap_err ( ) ;
7997
@@ -85,19 +103,28 @@ mod tests {
85103 let f = FieldElement :: random ( & mut rng) ;
86104 let expected = ( a + b + c) * ( d + e + f) ;
87105
88- assert_eq ! ( a. add( & b) . add( & c) . mul( & d. add( & e) . add( & f) ) , expected) ;
106+ assert_eq ! (
107+ LazyField :: add( a, & b)
108+ . add( & c)
109+ . mul( & LazyField :: add( d, & e) . add( & f) ) ,
110+ expected
111+ ) ;
112+ assert_eq ! ( add_triple_then_mul( a, b, c, d, e, f) , expected) ;
113+
114+ let a = EagerField ( a, PhantomData :: < typenum:: U1 > ) ;
115+ let b = EagerField ( b, PhantomData :: < typenum:: U1 > ) ;
116+ let c = EagerField ( c, PhantomData :: < typenum:: U1 > ) ;
117+ let d = EagerField ( d, PhantomData :: < typenum:: U1 > ) ;
118+ let e = EagerField ( e, PhantomData :: < typenum:: U1 > ) ;
119+ let f = EagerField ( f, PhantomData :: < typenum:: U1 > ) ;
89120
90121 assert_eq ! (
91- EagerField ( a, PhantomData :: <typenum:: U1 >)
92- . add( & EagerField ( b, PhantomData :: <typenum:: U1 >) )
93- . add( & EagerField ( c, PhantomData :: <typenum:: U1 >) )
94- . mul(
95- & EagerField ( d, PhantomData :: <typenum:: U1 >)
96- . add( & EagerField ( e, PhantomData :: <typenum:: U1 >) )
97- . add( & EagerField ( f, PhantomData :: <typenum:: U1 >) )
98- )
122+ LazyField :: add( a, & b)
123+ . add( & c)
124+ . mul( & LazyField :: add( d, & e) . add( & f) )
99125 . 0 ,
100126 expected
101127 ) ;
128+ assert_eq ! ( add_triple_then_mul( a, b, c, d, e, f) . 0 , expected) ;
102129 }
103130}
0 commit comments