@@ -10,7 +10,7 @@ use itertools::{enumerate, Itertools};
10
10
use num_bigint:: BigUint ;
11
11
use num_integer:: binomial;
12
12
use 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 } ;
14
14
15
15
/// Struct representing a boolean function with a big truth table.
16
16
///
@@ -461,6 +461,32 @@ impl BitXor for BigBooleanFunction {
461
461
}
462
462
}
463
463
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
+
464
490
/// In-place AND operator for Boolean functions truth tables.
465
491
///
466
492
/// # Panics
@@ -488,6 +514,31 @@ impl BitAnd for BigBooleanFunction {
488
514
}
489
515
}
490
516
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
+
491
542
/// NOT operator for Boolean functions.
492
543
///
493
544
/// This is equivalent to the [crate::BooleanFunctionImpl::reverse] operation: it reverses each output of the Boolean function.
@@ -936,6 +987,30 @@ mod tests {
936
987
assert_eq ! ( boolean_function3. variables_count( ) , 7 ) ;
937
988
}
938
989
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
+
939
1014
#[ test]
940
1015
fn test_and ( ) {
941
1016
let mut boolean_function = BigBooleanFunction :: from_truth_table (
@@ -960,6 +1035,30 @@ mod tests {
960
1035
assert_eq ! ( boolean_function3. variables_count( ) , 8 ) ;
961
1036
}
962
1037
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
+
963
1062
#[ test]
964
1063
fn test_biguint_truth_table ( ) {
965
1064
let boolean_function = BigBooleanFunction :: from_truth_table (
0 commit comments