@@ -10,7 +10,7 @@ use itertools::{enumerate, Itertools};
1010use num_bigint:: BigUint ;
1111use num_integer:: binomial;
1212use num_traits:: { FromPrimitive , One , Zero } ;
13- use std:: ops:: { BitAnd , BitAndAssign , BitXor , BitXorAssign , Not } ;
13+ use std:: ops:: { Add , AddAssign , BitAnd , BitAndAssign , BitXor , BitXorAssign , Mul , MulAssign , Not } ;
1414
1515/// Struct representing a boolean function with a big truth table.
1616///
@@ -461,6 +461,32 @@ impl BitXor for BigBooleanFunction {
461461 }
462462}
463463
464+ /// ADD operator for Boolean functions truth tables.
465+ ///
466+ /// It is equivalent to [crate::BigBooleanFunction::bitxor] operator.
467+ ///
468+ /// # Panics
469+ /// If the Boolean functions have different number of variables, and the `unsafe_disable_safety_checks` feature is not enabled.
470+ impl Add for BigBooleanFunction {
471+ type Output = Self ;
472+
473+ fn add ( self , rhs : Self ) -> Self :: Output {
474+ self ^ rhs
475+ }
476+ }
477+
478+ /// In-place ADD operator for Boolean functions truth tables.
479+ ///
480+ /// It is equivalent to [crate::BigBooleanFunction::bitxor_assign] operator.
481+ ///
482+ /// # Panics
483+ /// If the Boolean functions have different number of variables, and the `unsafe_disable_safety_checks` feature is not enabled.
484+ impl AddAssign for BigBooleanFunction {
485+ fn add_assign ( & mut self , rhs : Self ) {
486+ * self ^= rhs;
487+ }
488+ }
489+
464490/// In-place AND operator for Boolean functions truth tables.
465491///
466492/// # Panics
@@ -488,6 +514,31 @@ impl BitAnd for BigBooleanFunction {
488514 }
489515}
490516
517+ /// MUL operator for Boolean functions truth tables.
518+ ///
519+ /// It is equivalent to [crate::BigBooleanFunction::bitand] operator.
520+ ///
521+ /// # Panics
522+ /// If the Boolean functions have different number of variables, and the `unsafe_disable_safety_checks` feature is not enabled.
523+ impl Mul for BigBooleanFunction {
524+ type Output = Self ;
525+ fn mul ( self , rhs : Self ) -> Self :: Output {
526+ self & rhs
527+ }
528+ }
529+
530+ /// In-place MUL operator for Boolean functions truth tables.
531+ ///
532+ /// It is equivalent to [crate::BigBooleanFunction::bitand_assign] operator.
533+ ///
534+ /// # Panics
535+ /// If the Boolean functions have different number of variables, and the `unsafe_disable_safety_checks` feature is not enabled.
536+ impl MulAssign for BigBooleanFunction {
537+ fn mul_assign ( & mut self , rhs : Self ) {
538+ * self &= rhs;
539+ }
540+ }
541+
491542/// NOT operator for Boolean functions.
492543///
493544/// This is equivalent to the [crate::BooleanFunctionImpl::reverse] operation: it reverses each output of the Boolean function.
@@ -936,6 +987,30 @@ mod tests {
936987 assert_eq ! ( boolean_function3. variables_count( ) , 7 ) ;
937988 }
938989
990+ #[ test]
991+ fn test_add ( ) {
992+ let mut boolean_function = BigBooleanFunction :: from_truth_table (
993+ BigUint :: from_str_radix ( "80921c010276c440400810a80e200425" , 16 ) . unwrap ( ) ,
994+ 7 ,
995+ ) ;
996+ let boolean_function2 = BigBooleanFunction :: from_truth_table (
997+ BigUint :: from_str_radix ( "22442244118811882244224411881188" , 16 ) . unwrap ( ) ,
998+ 7 ,
999+ ) ;
1000+ let boolean_function3 = boolean_function. clone ( ) + boolean_function2. clone ( ) ;
1001+ boolean_function += boolean_function2;
1002+ assert_eq ! (
1003+ boolean_function. printable_hex_truth_table( ) ,
1004+ "a2d63e4513fed5c8624c32ec1fa815ad"
1005+ ) ;
1006+ assert_eq ! ( boolean_function. variables_count( ) , 7 ) ;
1007+ assert_eq ! (
1008+ boolean_function3. printable_hex_truth_table( ) ,
1009+ "a2d63e4513fed5c8624c32ec1fa815ad"
1010+ ) ;
1011+ assert_eq ! ( boolean_function3. variables_count( ) , 7 ) ;
1012+ }
1013+
9391014 #[ test]
9401015 fn test_and ( ) {
9411016 let mut boolean_function = BigBooleanFunction :: from_truth_table (
@@ -960,6 +1035,30 @@ mod tests {
9601035 assert_eq ! ( boolean_function3. variables_count( ) , 8 ) ;
9611036 }
9621037
1038+ #[ test]
1039+ fn test_mul ( ) {
1040+ let mut boolean_function = BigBooleanFunction :: from_truth_table (
1041+ BigUint :: from_str_radix ( "4f1ead396f247a0410bdb210c006eab568ab4bfa8acb7a13b14ede67096c6eed" , 16 ) . unwrap ( ) ,
1042+ 8 ,
1043+ ) ;
1044+ let boolean_function2 = BigBooleanFunction :: from_truth_table (
1045+ BigUint :: from_str_radix ( "c870974094ead8a96a450b2ef33486b4e61a4c5e97816f7a7bae007d4c53fc7d" , 16 ) . unwrap ( ) ,
1046+ 8 ,
1047+ ) ;
1048+ let boolean_function3 = boolean_function. clone ( ) * boolean_function2. clone ( ) ;
1049+ boolean_function *= boolean_function2;
1050+ assert_eq ! (
1051+ boolean_function. printable_hex_truth_table( ) ,
1052+ "481085000420580000050200c00482b4600a485a82816a12310e006508406c6d"
1053+ ) ;
1054+ assert_eq ! ( boolean_function. variables_count( ) , 8 ) ;
1055+ assert_eq ! (
1056+ boolean_function3. printable_hex_truth_table( ) ,
1057+ "481085000420580000050200c00482b4600a485a82816a12310e006508406c6d"
1058+ ) ;
1059+ assert_eq ! ( boolean_function3. variables_count( ) , 8 ) ;
1060+ }
1061+
9631062 #[ test]
9641063 fn test_biguint_truth_table ( ) {
9651064 let boolean_function = BigBooleanFunction :: from_truth_table (
0 commit comments