8
8
use itertools:: Itertools ;
9
9
use num_bigint:: BigUint ;
10
10
use num_traits:: Zero ;
11
- use crate :: { utils, BooleanFunction , BooleanFunctionImpl , BooleanFunctionType , SmallBooleanFunction } ;
11
+ use crate :: { utils, BooleanFunctionImpl , BooleanFunctionType , SmallBooleanFunction } ;
12
12
13
13
/// Representatives of all affine equivalence classes of boolean functions with 3 variables
14
14
pub const BOOLEAN_FUNCTIONS_3_VAR_AFFINE_EQ_CLASSES : [ SmallBooleanFunction ; 3 ] = [
@@ -112,7 +112,18 @@ pub struct AffineEquivalenceFactors {
112
112
///
113
113
/// # Note
114
114
/// If `f` anf `g` don't have the same input variable count, the function will return `None`.
115
- pub fn compute_affine_equivalence ( f : & BooleanFunction , g : & BooleanFunction ) -> Option < AffineEquivalenceFactors > {
115
+ ///
116
+ /// # Example
117
+ /// ```rust
118
+ /// use boolean_function::{BooleanFunction, SmallBooleanFunction};
119
+ /// use boolean_function::affine_equivalence_classes::compute_affine_equivalence;
120
+ /// // 4-variable bent functions equivalence class
121
+ /// let f = BooleanFunction::from_hex_string_truth_table("ac90").unwrap();
122
+ /// let g = SmallBooleanFunction::from_truth_table(0xdbd4, 4).unwrap();
123
+ ///
124
+ /// // f and g are affine-equivalent
125
+ /// assert!(compute_affine_equivalence(&f, &g).is_some());
126
+ pub fn compute_affine_equivalence ( f : & impl BooleanFunctionImpl , g : & impl BooleanFunctionImpl ) -> Option < AffineEquivalenceFactors > {
116
127
if f. variables_count ( ) != g. variables_count ( ) || f. variables_count ( ) == 0 {
117
128
return None ;
118
129
}
@@ -193,7 +204,7 @@ pub fn compute_affine_equivalence(f: &BooleanFunction, g: &BooleanFunction) -> O
193
204
#[ cfg( test) ]
194
205
mod tests {
195
206
use crate :: affine_equivalence_classes:: compute_affine_equivalence;
196
- use crate :: BooleanFunction ;
207
+ use crate :: { BooleanFunction , SmallBooleanFunction } ;
197
208
198
209
#[ test]
199
210
fn test_compute_affine_equivalence_not_same_var_count ( ) {
@@ -250,4 +261,17 @@ mod tests {
250
261
assert_eq ! ( factors. b, 10 ) ;
251
262
assert_eq ! ( factors. c, false ) ;
252
263
}
264
+
265
+ #[ test]
266
+ fn test_compute_affine_equivalence_small ( ) {
267
+ let f = SmallBooleanFunction :: from_truth_table ( 0x1234 , 4 ) . unwrap ( ) ;
268
+ let g = BooleanFunction :: from_hex_string_truth_table ( "1234" ) . unwrap ( ) ;
269
+ let factors = compute_affine_equivalence ( & f, & g) ;
270
+ assert ! ( factors. is_some( ) ) ;
271
+ let factors = factors. unwrap ( ) ;
272
+ assert_eq ! ( factors. d, [ 1 , 2 , 4 , 8 ] ) ; // Identity matrix
273
+ assert_eq ! ( factors. a, 0 ) ;
274
+ assert_eq ! ( factors. b, 0 ) ;
275
+ assert_eq ! ( factors. c, false ) ;
276
+ }
253
277
}
0 commit comments