@@ -791,7 +791,8 @@ impl BooleanFunction {
791
791
/// # Example
792
792
/// ```rust
793
793
/// use boolean_function::BooleanFunction;
794
- /// let boolean_function = BooleanFunction::from_hex_string_truth_table("0969817CC5893BA6").unwrap();
794
+ /// let boolean_function = BooleanFunction::from_hex_string_truth_table("0969817CC5893BA6")
795
+ /// .unwrap();
795
796
/// ```
796
797
pub fn from_hex_string_truth_table (
797
798
hex_truth_table : & str ,
@@ -877,7 +878,7 @@ impl BooleanFunction {
877
878
pub fn from_u64_truth_table (
878
879
truth_table : u64 ,
879
880
num_variables : usize ,
880
- ) -> Result < BooleanFunction , BooleanFunctionError > {
881
+ ) -> Result < Self , BooleanFunctionError > {
881
882
Ok ( SmallBooleanFunction :: from_truth_table ( truth_table, num_variables) ?. into ( ) )
882
883
}
883
884
@@ -898,7 +899,7 @@ impl BooleanFunction {
898
899
pub fn from_biguint_truth_table (
899
900
truth_table : & BigUint ,
900
901
num_variables : usize ,
901
- ) -> Result < BooleanFunction , BooleanFunctionError > {
902
+ ) -> Result < Self , BooleanFunctionError > {
902
903
#[ cfg( not( feature = "unsafe_disable_safety_checks" ) ) ]
903
904
if truth_table. bits ( ) > ( 1 << num_variables) {
904
905
return Err ( BooleanFunctionError :: TooBigTruthTableForVarCount ) ;
@@ -929,17 +930,36 @@ impl BooleanFunction {
929
930
///
930
931
/// # Returns
931
932
/// The BooleanFunction corresponding to the ANF string representation, or an error if the input string doesn't respect the format and `unsafe_disable_safety_checks` feature is not activated.
932
- pub fn from_anf_polynomial_str ( anf_polynomial : & str , num_variables : usize ) -> Result < BooleanFunction , BooleanFunctionError > {
933
+ ///
934
+ /// # Example
935
+ /// ```rust
936
+ /// use boolean_function::{BooleanFunction, BooleanFunctionImpl};
937
+ ///
938
+ /// let rule_30 = BooleanFunction::from_anf_polynomial_str("x0*x1 + x0 + x1 + x2", 3).unwrap();
939
+ /// assert_eq!(rule_30.printable_hex_truth_table(), "1e");
940
+ /// ```
941
+ pub fn from_anf_polynomial_str ( anf_polynomial : & str , num_variables : usize ) -> Result < Self , BooleanFunctionError > {
933
942
Ok ( AnfPolynomial :: from_str ( anf_polynomial, num_variables) ?. to_boolean_function ( ) )
934
943
}
944
+
945
+ /// Computes Boolean Function from ANF polynomial
946
+ ///
947
+ /// # Parameters:
948
+ /// - `anf_polynomial`: The polynomial in Algebraic Normal Form
949
+ ///
950
+ /// # Returns
951
+ /// The BooleanFunction corresponding to the ANF polynomial
952
+ pub fn from_anf_polynomial ( anf_polynomial : & AnfPolynomial ) -> Self {
953
+ anf_polynomial. to_boolean_function ( )
954
+ }
935
955
}
936
956
937
- // TODO from AnfPolynomial
957
+ // TODO from ANF in Small and Big Boolean functions
938
958
939
959
#[ cfg( test) ]
940
960
mod tests {
941
961
use crate :: BooleanFunctionError :: InvalidWalshValuesCount ;
942
- use crate :: { BooleanFunction , BooleanFunctionImpl , BooleanFunctionType } ;
962
+ use crate :: { AnfPolynomial , BooleanFunction , BooleanFunctionImpl , BooleanFunctionType } ;
943
963
use num_bigint:: BigUint ;
944
964
use num_traits:: Num ;
945
965
use std:: collections:: HashMap ;
@@ -2179,4 +2199,15 @@ mod tests {
2179
2199
let boolean_function = BooleanFunction :: from_anf_polynomial_str ( anf_str, 8 ) . unwrap ( ) ;
2180
2200
assert_eq ! ( boolean_function. printable_hex_truth_table( ) , "7fffffffffffffffffffffffffffffff80000000000000000000000000000000" ) ;
2181
2201
}
2202
+
2203
+ #[ test]
2204
+ fn test_from_anf_polynomial ( ) {
2205
+ let rule_30_anf = AnfPolynomial :: from_str ( "x0*x1 + x0 + x1 + x2" , 3 ) . unwrap ( ) ;
2206
+ let rule_30_function = BooleanFunction :: from_anf_polynomial ( & rule_30_anf) ;
2207
+ assert_eq ! ( rule_30_function. printable_hex_truth_table( ) , "1e" ) ;
2208
+
2209
+ let anf = AnfPolynomial :: from_str ( "x0*x1*x2*x3*x4*x5*x6 + x7" , 8 ) . unwrap ( ) ;
2210
+ let boolean_function = BooleanFunction :: from_anf_polynomial ( & anf) ;
2211
+ assert_eq ! ( boolean_function. printable_hex_truth_table( ) , "7fffffffffffffffffffffffffffffff80000000000000000000000000000000" ) ;
2212
+ }
2182
2213
}
0 commit comments