@@ -96,14 +96,15 @@ impl BigBooleanFunction {
96
96
/// Computes the [annihilator](crate::BooleanFunctionImpl::annihilator) of the Boolean function for a given maximum degree.
97
97
///
98
98
/// # Parameters
99
- /// * `max_degree` - The maximum degree of the wished annihilator.
99
+ /// * `max_degree` - An optional maximum degree of the annihilator to search for. If set to `None`, the value is set to the variable count .
100
100
///
101
101
/// # Returns
102
102
/// A tuple containing the annihilator function, its degree and the dimension of the annihilator vector space, or `None` no annihilator was found.
103
103
pub fn annihilator_inner (
104
104
& self ,
105
- max_degree : usize ,
105
+ max_degree : Option < usize > ,
106
106
) -> Option < ( BigBooleanFunction , usize , usize ) > {
107
+ let max_degree = max_degree. unwrap_or ( self . variables_count ) ;
107
108
if self . truth_table == BigUint :: zero ( ) {
108
109
let max_possible_function_tt =
109
110
( BigUint :: one ( ) << ( 1 << self . variables_count ) ) - BigUint :: one ( ) ;
@@ -408,7 +409,7 @@ impl BooleanFunctionImpl for BigBooleanFunction {
408
409
AnfPolynomial :: from_anf_big ( & anf_form, self . variables_count )
409
410
}
410
411
411
- fn annihilator ( & self , max_degree : usize ) -> Option < ( BooleanFunction , usize , usize ) > {
412
+ fn annihilator ( & self , max_degree : Option < usize > ) -> Option < ( BooleanFunction , usize , usize ) > {
412
413
let annihilator = self . annihilator_inner ( max_degree) ?;
413
414
Some ( ( ( annihilator. 0 ) . into ( ) , annihilator. 1 , annihilator. 2 ) )
414
415
}
@@ -745,7 +746,7 @@ mod tests {
745
746
BigUint :: from_str_radix ( "00000000000000000000000000000000" , 16 ) . unwrap ( ) ,
746
747
7 ,
747
748
) ;
748
- let annihilator = boolean_function. annihilator_inner ( 0 ) . unwrap ( ) ;
749
+ let annihilator = boolean_function. annihilator_inner ( Some ( 0 ) ) . unwrap ( ) ;
749
750
assert_eq ! (
750
751
annihilator. 0 . printable_hex_truth_table( ) ,
751
752
"ffffffffffffffffffffffffffffffff"
@@ -757,25 +758,40 @@ mod tests {
757
758
BigUint :: from_str_radix ( "ffffffffffffffffffffffffffffffff" , 16 ) . unwrap ( ) ,
758
759
7 ,
759
760
) ;
760
- let annihilator = boolean_function. annihilator_inner ( 7 ) ;
761
+ let annihilator = boolean_function. annihilator_inner ( Some ( 7 ) ) ;
762
+ assert ! ( annihilator. is_none( ) ) ;
763
+
764
+ let boolean_function = BigBooleanFunction :: from_truth_table (
765
+ BigUint :: from_str_radix ( "ffffffffffffffffffffffffffffffff" , 16 ) . unwrap ( ) ,
766
+ 7 ,
767
+ ) ;
768
+ let annihilator = boolean_function. annihilator_inner ( None ) ;
761
769
assert ! ( annihilator. is_none( ) ) ;
762
770
763
771
let boolean_function = BigBooleanFunction :: from_truth_table (
764
772
BigUint :: from_str_radix ( "7969817CC5893BA6AC326E47619F5AD0" , 16 ) . unwrap ( ) ,
765
773
7 ,
766
774
) ;
767
- let annihilator = boolean_function. annihilator_inner ( 2 ) ;
775
+ let annihilator = boolean_function. annihilator_inner ( Some ( 2 ) ) ;
768
776
assert ! ( annihilator. is_none( ) ) ;
769
777
770
- let annihilator = boolean_function. annihilator_inner ( 3 ) . unwrap ( ) ;
778
+ let annihilator = boolean_function. annihilator_inner ( Some ( 3 ) ) . unwrap ( ) ;
771
779
assert_eq ! (
772
780
annihilator. 0 . printable_hex_truth_table( ) ,
773
781
"80921c010276c440400810a80e200425"
774
782
) ;
775
783
assert_eq ! ( annihilator. 1 , 3 ) ;
776
784
assert_eq ! ( annihilator. 2 , 2 ) ;
777
785
778
- let annihilator = boolean_function. annihilator_inner ( 7 ) . unwrap ( ) ;
786
+ let annihilator = boolean_function. annihilator_inner ( Some ( 7 ) ) . unwrap ( ) ;
787
+ assert_eq ! (
788
+ annihilator. 0 . printable_hex_truth_table( ) ,
789
+ "80921c010276c440400810a80e200425"
790
+ ) ;
791
+ assert_eq ! ( annihilator. 1 , 3 ) ;
792
+ assert_eq ! ( annihilator. 2 , 64 ) ;
793
+
794
+ let annihilator = boolean_function. annihilator_inner ( None ) . unwrap ( ) ;
779
795
assert_eq ! (
780
796
annihilator. 0 . printable_hex_truth_table( ) ,
781
797
"80921c010276c440400810a80e200425"
@@ -787,10 +803,10 @@ mod tests {
787
803
BigUint :: from_str_radix ( "80921c010276c440400810a80e200425" , 16 ) . unwrap ( ) ,
788
804
7 ,
789
805
) ;
790
- let annihilator = boolean_function. annihilator_inner ( 1 ) ;
806
+ let annihilator = boolean_function. annihilator_inner ( Some ( 1 ) ) ;
791
807
assert ! ( annihilator. is_none( ) ) ;
792
808
793
- let annihilator = boolean_function. annihilator_inner ( 2 ) . unwrap ( ) ;
809
+ let annihilator = boolean_function. annihilator_inner ( Some ( 2 ) ) . unwrap ( ) ;
794
810
assert_eq ! (
795
811
annihilator. 0 . printable_hex_truth_table( ) ,
796
812
"22442244118811882244224411881188"
@@ -802,26 +818,34 @@ mod tests {
802
818
BigUint :: from_str_radix ( "0000000000000000ffffffffffffffff" , 16 ) . unwrap ( ) ,
803
819
7 ,
804
820
) ;
805
- let annihilator = boolean_function. annihilator_inner ( 0 ) ;
821
+ let annihilator = boolean_function. annihilator_inner ( Some ( 0 ) ) ;
806
822
assert ! ( annihilator. is_none( ) ) ;
807
823
808
- let annihilator = boolean_function. annihilator_inner ( 1 ) . unwrap ( ) ;
824
+ let annihilator = boolean_function. annihilator_inner ( Some ( 1 ) ) . unwrap ( ) ;
809
825
assert_eq ! (
810
826
annihilator. 0 . printable_hex_truth_table( ) ,
811
827
"ffffffffffffffff0000000000000000"
812
828
) ;
813
829
assert_eq ! ( annihilator. 1 , 1 ) ;
814
830
assert_eq ! ( annihilator. 2 , 1 ) ;
815
831
816
- let annihilator = boolean_function. annihilator_inner ( 4 ) . unwrap ( ) ;
832
+ let annihilator = boolean_function. annihilator_inner ( Some ( 4 ) ) . unwrap ( ) ;
817
833
assert_eq ! (
818
834
annihilator. 0 . printable_hex_truth_table( ) ,
819
835
"ffffffffffffffff0000000000000000"
820
836
) ;
821
837
assert_eq ! ( annihilator. 1 , 1 ) ;
822
838
assert_eq ! ( annihilator. 2 , 42 ) ;
823
839
824
- let annihilator = boolean_function. annihilator_inner ( 7 ) . unwrap ( ) ;
840
+ let annihilator = boolean_function. annihilator_inner ( Some ( 7 ) ) . unwrap ( ) ;
841
+ assert_eq ! (
842
+ annihilator. 0 . printable_hex_truth_table( ) ,
843
+ "ffffffffffffffff0000000000000000"
844
+ ) ;
845
+ assert_eq ! ( annihilator. 1 , 1 ) ;
846
+ assert_eq ! ( annihilator. 2 , 64 ) ;
847
+
848
+ let annihilator = boolean_function. annihilator_inner ( None ) . unwrap ( ) ;
825
849
assert_eq ! (
826
850
annihilator. 0 . printable_hex_truth_table( ) ,
827
851
"ffffffffffffffff0000000000000000"
@@ -837,20 +861,20 @@ mod tests {
837
861
. unwrap ( ) ,
838
862
8 ,
839
863
) ;
840
- let annihilator = boolean_function. annihilator_inner ( 0 ) ;
864
+ let annihilator = boolean_function. annihilator_inner ( Some ( 0 ) ) ;
841
865
assert ! ( annihilator. is_none( ) ) ;
842
- let annihilator = boolean_function. annihilator_inner ( 1 ) ;
866
+ let annihilator = boolean_function. annihilator_inner ( Some ( 1 ) ) ;
843
867
assert ! ( annihilator. is_none( ) ) ;
844
868
845
- let annihilator = boolean_function. annihilator_inner ( 2 ) . unwrap ( ) ;
869
+ let annihilator = boolean_function. annihilator_inner ( Some ( 2 ) ) . unwrap ( ) ;
846
870
assert_eq ! (
847
871
annihilator. 0 . printable_hex_truth_table( ) ,
848
872
"2244224411881188d2b4d2b4e178e178d2b4d2b4e178e1782244224411881188"
849
873
) ;
850
874
assert_eq ! ( annihilator. 1 , 2 ) ;
851
875
assert_eq ! ( annihilator. 2 , 2 ) ;
852
876
853
- let annihilator = boolean_function. annihilator_inner ( 5 ) . unwrap ( ) ;
877
+ let annihilator = boolean_function. annihilator_inner ( Some ( 5 ) ) . unwrap ( ) ;
854
878
assert_eq ! (
855
879
annihilator. 0 . printable_hex_truth_table( ) ,
856
880
"2244224411881188d2b4d2b4e178e178d2b4d2b4e178e1782244224411881188"
@@ -866,7 +890,7 @@ mod tests {
866
890
. unwrap ( ) ,
867
891
8 ,
868
892
) ;
869
- let annihilator = boolean_function. annihilator_inner ( 4 ) ;
893
+ let annihilator = boolean_function. annihilator_inner ( Some ( 4 ) ) ;
870
894
assert ! ( annihilator. is_none( ) ) ;
871
895
872
896
let boolean_function = BigBooleanFunction :: from_truth_table (
@@ -877,7 +901,7 @@ mod tests {
877
901
. unwrap ( ) ,
878
902
8 ,
879
903
) ;
880
- let annihilator = boolean_function. annihilator_inner ( 4 ) . unwrap ( ) ;
904
+ let annihilator = boolean_function. annihilator_inner ( Some ( 4 ) ) . unwrap ( ) ;
881
905
assert_eq ! (
882
906
annihilator. 0 . printable_hex_truth_table( ) ,
883
907
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
0 commit comments