@@ -212,12 +212,37 @@ pub trait BooleanFunctionImpl: Debug {
212
212
///
213
213
/// # Returns
214
214
/// A vector containing the Walsh-Fourier values for all points.
215
+ #[ deprecated( note = "Use `fast_walsh_fourier_values` instead" ) ]
215
216
fn walsh_fourier_values ( & self ) -> Vec < i32 > {
216
217
( 0 ..=self . get_max_input_value ( ) )
217
218
. map ( |w| self . walsh_fourier_transform ( w) )
218
219
. collect ( )
219
220
}
220
221
222
+ /// Computes the Walsh-Fourier values for all points using fast Fourier transform.
223
+ ///
224
+ /// # Returns
225
+ /// A vector containing the Walsh-Fourier values for all points.
226
+ fn fast_walsh_fourier_values ( & self ) -> Vec < i32 > {
227
+ let mut values = vec ! [ 0 ; ( self . get_max_input_value( ) + 1 ) as usize ] ;
228
+ for i in 0 ..=self . get_max_input_value ( ) {
229
+ values[ i as usize ] = self . compute_cellular_automata_rule ( i) as i32 ;
230
+ }
231
+ let mut h = 1usize ;
232
+ while h <= self . get_max_input_value ( ) as usize {
233
+ for i in ( 0 ..=self . get_max_input_value ( ) as usize ) . step_by ( h * 2 ) {
234
+ for j in 0 ..h {
235
+ let a = values[ i + j] ;
236
+ let b = values[ i + j + h] ;
237
+ values[ i + j] = a + b;
238
+ values[ i + j + h] = a - b;
239
+ }
240
+ }
241
+ h *= 2 ;
242
+ }
243
+ values
244
+ }
245
+
221
246
/// Computes the autocorrelation transform of the Boolean function for a given point.
222
247
/// The autocorrelation transform of a Boolean function $f$, for a given point $\omega$, is defined as:
223
248
///
@@ -2408,6 +2433,45 @@ mod tests {
2408
2433
) ;
2409
2434
}
2410
2435
2436
+ #[ test]
2437
+ fn test_fast_walsh_fourier_values ( ) {
2438
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "ff" ) . unwrap ( ) ;
2439
+ assert_eq ! (
2440
+ boolean_function. fast_walsh_fourier_values( ) ,
2441
+ [ 8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
2442
+ ) ;
2443
+
2444
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "00" ) . unwrap ( ) ;
2445
+ assert_eq ! (
2446
+ boolean_function. fast_walsh_fourier_values( ) ,
2447
+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
2448
+ ) ;
2449
+
2450
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "0f" ) . unwrap ( ) ;
2451
+ assert_eq ! (
2452
+ boolean_function. fast_walsh_fourier_values( ) ,
2453
+ [ 4 , 0 , 0 , 0 , 4 , 0 , 0 , 0 ]
2454
+ ) ;
2455
+
2456
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "55" ) . unwrap ( ) ;
2457
+ assert_eq ! (
2458
+ boolean_function. fast_walsh_fourier_values( ) ,
2459
+ [ 4 , 4 , 0 , 0 , 0 , 0 , 0 , 0 ]
2460
+ ) ;
2461
+
2462
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "aa" ) . unwrap ( ) ;
2463
+ assert_eq ! (
2464
+ boolean_function. fast_walsh_fourier_values( ) ,
2465
+ [ 4 , -4 , 0 , 0 , 0 , 0 , 0 , 0 ]
2466
+ ) ;
2467
+
2468
+ let boolean_function = BooleanFunction :: from_hex_string_truth_table ( "8001" ) . unwrap ( ) ;
2469
+ assert_eq ! (
2470
+ boolean_function. fast_walsh_fourier_values( ) ,
2471
+ [ 2 , 0 , 0 , 2 , 0 , 2 , 2 , 0 , 0 , 2 , 2 , 0 , 2 , 0 , 0 , 2 ]
2472
+ ) ;
2473
+ }
2474
+
2411
2475
#[ test]
2412
2476
fn test_boolean_function_from_reverse_walsh_fourier_transform ( ) {
2413
2477
let boolean_function =
0 commit comments