@@ -791,7 +791,8 @@ impl BooleanFunction {
791791 /// # Example
792792 /// ```rust
793793 /// 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();
795796 /// ```
796797 pub fn from_hex_string_truth_table (
797798 hex_truth_table : & str ,
@@ -877,7 +878,7 @@ impl BooleanFunction {
877878 pub fn from_u64_truth_table (
878879 truth_table : u64 ,
879880 num_variables : usize ,
880- ) -> Result < BooleanFunction , BooleanFunctionError > {
881+ ) -> Result < Self , BooleanFunctionError > {
881882 Ok ( SmallBooleanFunction :: from_truth_table ( truth_table, num_variables) ?. into ( ) )
882883 }
883884
@@ -898,7 +899,7 @@ impl BooleanFunction {
898899 pub fn from_biguint_truth_table (
899900 truth_table : & BigUint ,
900901 num_variables : usize ,
901- ) -> Result < BooleanFunction , BooleanFunctionError > {
902+ ) -> Result < Self , BooleanFunctionError > {
902903 #[ cfg( not( feature = "unsafe_disable_safety_checks" ) ) ]
903904 if truth_table. bits ( ) > ( 1 << num_variables) {
904905 return Err ( BooleanFunctionError :: TooBigTruthTableForVarCount ) ;
@@ -929,17 +930,36 @@ impl BooleanFunction {
929930 ///
930931 /// # Returns
931932 /// 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 > {
933942 Ok ( AnfPolynomial :: from_str ( anf_polynomial, num_variables) ?. to_boolean_function ( ) )
934943 }
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+ }
935955}
936956
937- // TODO from AnfPolynomial
957+ // TODO from ANF in Small and Big Boolean functions
938958
939959#[ cfg( test) ]
940960mod tests {
941961 use crate :: BooleanFunctionError :: InvalidWalshValuesCount ;
942- use crate :: { BooleanFunction , BooleanFunctionImpl , BooleanFunctionType } ;
962+ use crate :: { AnfPolynomial , BooleanFunction , BooleanFunctionImpl , BooleanFunctionType } ;
943963 use num_bigint:: BigUint ;
944964 use num_traits:: Num ;
945965 use std:: collections:: HashMap ;
@@ -2179,4 +2199,15 @@ mod tests {
21792199 let boolean_function = BooleanFunction :: from_anf_polynomial_str ( anf_str, 8 ) . unwrap ( ) ;
21802200 assert_eq ! ( boolean_function. printable_hex_truth_table( ) , "7fffffffffffffffffffffffffffffff80000000000000000000000000000000" ) ;
21812201 }
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+ }
21822213}
0 commit comments