Skip to content

Commit 44fe9e0

Browse files
committed
Improve API and documentation
1 parent 81fdd65 commit 44fe9e0

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/affine_equivalence_classes.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use itertools::Itertools;
99
use num_bigint::BigUint;
1010
use num_traits::Zero;
11-
use crate::{utils, BooleanFunction, BooleanFunctionImpl, BooleanFunctionType, SmallBooleanFunction};
11+
use crate::{utils, BooleanFunctionImpl, BooleanFunctionType, SmallBooleanFunction};
1212

1313
/// Representatives of all affine equivalence classes of boolean functions with 3 variables
1414
pub const BOOLEAN_FUNCTIONS_3_VAR_AFFINE_EQ_CLASSES: [SmallBooleanFunction; 3] = [
@@ -112,7 +112,18 @@ pub struct AffineEquivalenceFactors {
112112
///
113113
/// # Note
114114
/// 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> {
116127
if f.variables_count() != g.variables_count() || f.variables_count() == 0 {
117128
return None;
118129
}
@@ -193,7 +204,7 @@ pub fn compute_affine_equivalence(f: &BooleanFunction, g: &BooleanFunction) -> O
193204
#[cfg(test)]
194205
mod tests {
195206
use crate::affine_equivalence_classes::compute_affine_equivalence;
196-
use crate::BooleanFunction;
207+
use crate::{BooleanFunction, SmallBooleanFunction};
197208

198209
#[test]
199210
fn test_compute_affine_equivalence_not_same_var_count() {
@@ -250,4 +261,17 @@ mod tests {
250261
assert_eq!(factors.b, 10);
251262
assert_eq!(factors.c, false);
252263
}
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+
}
253277
}

0 commit comments

Comments
 (0)