pub struct SmallBooleanFunction { /* private fields */ }
Expand description
Struct representing a boolean function with a big truth table.
The struct internally stores the truth table as an u64, meaning that the maximum number of variables is 6.
For more than 6 variables, use the crate::BigBooleanFunction struct, or the crate::BooleanFunction type to store both small and big boolean functions.
Implementations§
Source§impl SmallBooleanFunction
impl SmallBooleanFunction
Sourcepub fn from_truth_table(
truth_table: u64,
variables_count: usize,
) -> Result<Self, BooleanFunctionError>
pub fn from_truth_table( truth_table: u64, variables_count: usize, ) -> Result<Self, BooleanFunctionError>
Creates a new SmallBooleanFunction from a truth table and the number of variables.
§Parameters
truth_table
- The truth table of the Boolean function, where the lower bit represents the output of the Boolean function for the input 0.variables_count
- The number of variables of the Boolean function.
§Returns
A SmallBooleanFunction instance from the truth table and the number of variables or an error if:
- The number of variables is greater than 6.
- The truth table is too big for the number of variables, and the
unsafe_disable_safety_checks
feature is not enabled.
Sourcepub fn get_truth_table_u64(&self) -> u64
pub fn get_truth_table_u64(&self) -> u64
Returns the truth table of the Boolean function, as an u64.
Sourcepub fn derivative_inner(
&self,
direction: u32,
) -> Result<Self, BooleanFunctionError>
pub fn derivative_inner( &self, direction: u32, ) -> Result<Self, BooleanFunctionError>
Computes the derivative of the Boolean function for a given direction.
§Parameters
direction
- The direction of the derivative.
§Returns
The derivative of the Boolean function for the given direction, or an error if the direction is greater than the maximum input value and the unsafe_disable_safety_checks
feature is not enabled.
Sourcepub fn reverse_inner(&self) -> Self
pub fn reverse_inner(&self) -> Self
Sourcepub fn annihilator_inner(
&self,
max_degree: Option<usize>,
) -> Option<(SmallBooleanFunction, usize, usize)>
pub fn annihilator_inner( &self, max_degree: Option<usize>, ) -> Option<(SmallBooleanFunction, usize, usize)>
Computes the annihilator of the Boolean function for a given maximum degree.
§Parameters
max_degree
- An optional maximum degree of the annihilator to search for. If set toNone
, the value is set to the variable count.
§Returns
A tuple containing the annihilator function, its degree and the dimension of the annihilator vector space, or None
no annihilator was found.
Sourcepub fn from_walsh_hadamard_values(
walsh_values: &[i32],
) -> Result<Self, BooleanFunctionError>
pub fn from_walsh_hadamard_values( walsh_values: &[i32], ) -> Result<Self, BooleanFunctionError>
Computes a SmallBooleanFunction from Walsh-Hadamard values, by applying the inverse Walsh-Hadamard transform.
§Parameters
walsh_values
- The Walsh-Hadamard values of the Boolean function.
§Returns
The Boolean function created from the Walsh-Hadamard values list, or an error if:
- the list length is less than 4
- the list length is not a power of 2.
- the number of variables is greater than 6 (meaning that the list length is greater than 64).
Sourcepub fn from_walsh_fourier_values(
walsh_values: &[i32],
) -> Result<Self, BooleanFunctionError>
pub fn from_walsh_fourier_values( walsh_values: &[i32], ) -> Result<Self, BooleanFunctionError>
Computes a SmallBooleanFunction from Walsh-Fourier values, by applying the inverse Walsh-Fourier transform.
§Parameters
walsh_values
- The Walsh-Hadamard values of the Boolean function.
§Returns
The Boolean function created from the Walsh-Hadamard values list, or an error if:
- the list length is less than 4
- the list length is not a power of 2.
- the number of variables is greater than 6 (meaning that the list length is greater than 64).
Sourcepub fn get_1_local_neighbor_inner(&self, position: u32) -> Self
pub fn get_1_local_neighbor_inner(&self, position: u32) -> Self
Returns a 1-local neighbor of the Boolean function, at a specific position
§Parameters
position
: The position $i$ at which to compute the 1-local neighbor.
§Returns
The 1-local neighbor of the Boolean function at the given position.
§Panics
If the position is greater than the maximum input value, and the unsafe_disable_safety_checks
feature is not enabled.
Sourcepub fn close_balanced_functions_iterator_inner(
&self,
) -> Result<SmallCloseBalancedFunctionIterator, BooleanFunctionError>
pub fn close_balanced_functions_iterator_inner( &self, ) -> Result<SmallCloseBalancedFunctionIterator, BooleanFunctionError>
Returns an iterator over the closest possible balanced Boolean functions.
See BooleanFunctionImpl::close_balanced_functions_iterator for more details.
§Returns
An iterator over close balanced Boolean functions, or an error if the function is already balanced.
§Note
It is assumed that the function truth table is correctly sanitized, so be careful if you generated it with unsafe_disable_safety_checks
feature activated.
Sourcepub fn from_anf_polynomial_str_inner(
anf_polynomial: &str,
num_variables: usize,
) -> Result<Self, BooleanFunctionError>
pub fn from_anf_polynomial_str_inner( anf_polynomial: &str, num_variables: usize, ) -> Result<Self, BooleanFunctionError>
Computes SmallBooleanFunction from string ANF representation
The ANF string representation must be in exact form “x0*x2*x3 + x2*x3 + x1 + 1
”.
X’s index starts at 0, meaning the maximum index is variable count - 1.
§Parameters:
anf_polynomial
: The string representation of the ANF formnum_variables
: Variable count of the polynomial
§Returns
The SmallBooleanFunction 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. - the polynomial variable count is greater than 6
Sourcepub fn from_anf_polynomial_inner(
anf_polynomial: &AnfPolynomial,
) -> Result<Self, BooleanFunctionError>
pub fn from_anf_polynomial_inner( anf_polynomial: &AnfPolynomial, ) -> Result<Self, BooleanFunctionError>
Trait Implementations§
Source§impl Add for SmallBooleanFunction
ADD operator for Boolean functions truth tables.
impl Add for SmallBooleanFunction
ADD operator for Boolean functions truth tables.
It is equivalent to crate::SmallBooleanFunction::bitxor operator.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§impl AddAssign for SmallBooleanFunction
In-place ADD operator for Boolean functions truth tables.
impl AddAssign for SmallBooleanFunction
In-place ADD operator for Boolean functions truth tables.
It is equivalent to crate::SmallBooleanFunction::bitxor_assign operator.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl BitAnd for SmallBooleanFunction
AND operator for Boolean functions truth tables.
impl BitAnd for SmallBooleanFunction
AND operator for Boolean functions truth tables.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§impl BitAndAssign for SmallBooleanFunction
In-place AND operator for Boolean functions truth tables.
impl BitAndAssign for SmallBooleanFunction
In-place AND operator for Boolean functions truth tables.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moreSource§impl BitXor for SmallBooleanFunction
XOR operator for Boolean functions truth tables.
impl BitXor for SmallBooleanFunction
XOR operator for Boolean functions truth tables.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§impl BitXorAssign for SmallBooleanFunction
In-place XOR operator for Boolean functions truth tables.
impl BitXorAssign for SmallBooleanFunction
In-place XOR operator for Boolean functions truth tables.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moreSource§impl BooleanFunctionImpl for SmallBooleanFunction
impl BooleanFunctionImpl for SmallBooleanFunction
Source§fn variables_count(&self) -> usize
fn variables_count(&self) -> usize
Source§fn get_boolean_function_type(&self) -> BooleanFunctionType
fn get_boolean_function_type(&self) -> BooleanFunctionType
Source§fn is_balanced(&self) -> bool
fn is_balanced(&self) -> bool
true
if the Boolean function is balanced, ie it has an equal number of 0 and 1 outputs.Source§fn compute_cellular_automata_rule(&self, input_bits: u32) -> bool
fn compute_cellular_automata_rule(&self, input_bits: u32) -> bool
Source§fn derivative(
&self,
direction: u32,
) -> Result<BooleanFunction, BooleanFunctionError>
fn derivative( &self, direction: u32, ) -> Result<BooleanFunction, BooleanFunctionError>
Source§fn is_linear(&self) -> bool
fn is_linear(&self) -> bool
true
if the Boolean function is linear, ie its algebraic degree is 0 or 1.Source§fn reverse(&self) -> BooleanFunction
fn reverse(&self) -> BooleanFunction
Source§fn algebraic_normal_form(&self) -> AnfPolynomial
fn algebraic_normal_form(&self) -> AnfPolynomial
Source§fn annihilator(
&self,
max_degree: Option<usize>,
) -> Option<(BooleanFunction, usize, usize)>
fn annihilator( &self, max_degree: Option<usize>, ) -> Option<(BooleanFunction, usize, usize)>
Source§fn get_1_local_neighbor(&self, position: u32) -> BooleanFunction
fn get_1_local_neighbor(&self, position: u32) -> BooleanFunction
Source§fn iter(&self) -> BooleanFunctionIterator ⓘ
fn iter(&self) -> BooleanFunctionIterator ⓘ
Source§fn printable_hex_truth_table(&self) -> String
fn printable_hex_truth_table(&self) -> String
Source§fn biguint_truth_table(&self) -> BigUint
fn biguint_truth_table(&self) -> BigUint
Source§fn close_balanced_functions_iterator(
&self,
) -> Result<CloseBalancedFunctionIterator, BooleanFunctionError>
fn close_balanced_functions_iterator( &self, ) -> Result<CloseBalancedFunctionIterator, BooleanFunctionError>
Source§fn get_max_input_value(&self) -> u32
fn get_max_input_value(&self) -> u32
Source§fn walsh_hadamard_transform(&self, w: u32) -> i32
fn walsh_hadamard_transform(&self, w: u32) -> i32
Source§fn walsh_hadamard_values(&self) -> Vec<i32>
fn walsh_hadamard_values(&self) -> Vec<i32>
Source§fn absolute_walsh_hadamard_spectrum(&self) -> HashMap<u32, usize>
fn absolute_walsh_hadamard_spectrum(&self) -> HashMap<u32, usize>
Source§fn walsh_fourier_transform(&self, w: u32) -> i32
fn walsh_fourier_transform(&self, w: u32) -> i32
Source§fn walsh_fourier_values(&self) -> Vec<i32>
fn walsh_fourier_values(&self) -> Vec<i32>
Source§fn auto_correlation_transform(&self, w: u32) -> i32
fn auto_correlation_transform(&self, w: u32) -> i32
Source§fn absolute_autocorrelation(&self) -> HashMap<u32, usize>
fn absolute_autocorrelation(&self) -> HashMap<u32, usize>
Source§fn absolute_indicator(&self) -> u32
fn absolute_indicator(&self) -> u32
Source§fn algebraic_degree(&self) -> usize
fn algebraic_degree(&self) -> usize
Source§fn is_symmetric(&self) -> bool
fn is_symmetric(&self) -> bool
true
if the Boolean function is symmetric. Read moreSource§fn nonlinearity(&self) -> u32
fn nonlinearity(&self) -> u32
Source§fn is_bent(&self) -> bool
fn is_bent(&self) -> bool
true
if the Boolean function is bent, meaning maximally nonlinear, or perfectly nonlinear. Read moreSource§fn is_near_bent(&self) -> bool
fn is_near_bent(&self) -> bool
true
if the Boolean function is near-bent. Read moreSource§fn algebraic_immunity(&self) -> usize
fn algebraic_immunity(&self) -> usize
Source§fn is_plateaued(&self) -> bool
fn is_plateaued(&self) -> bool
true
if the Boolean function is plateaued. Read moreSource§fn sum_of_square_indicator(&self) -> usize
fn sum_of_square_indicator(&self) -> usize
Source§fn has_linear_structure(&self) -> bool
fn has_linear_structure(&self) -> bool
true
if the Boolean function has a linear structure. Read moreSource§fn is_linear_structure(&self, value: u32) -> bool
fn is_linear_structure(&self, value: u32) -> bool
Source§fn linear_structures(&self) -> Vec<u32>
fn linear_structures(&self) -> Vec<u32>
Source§fn correlation_immunity(&self) -> usize
fn correlation_immunity(&self) -> usize
Source§fn resiliency_order(&self) -> Option<usize>
fn resiliency_order(&self) -> Option<usize>
Source§fn propagation_criterion(&self) -> usize
fn propagation_criterion(&self) -> usize
Source§impl Clone for SmallBooleanFunction
impl Clone for SmallBooleanFunction
Source§fn clone(&self) -> SmallBooleanFunction
fn clone(&self) -> SmallBooleanFunction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SmallBooleanFunction
impl Debug for SmallBooleanFunction
Source§impl Deref for SmallBooleanFunction
impl Deref for SmallBooleanFunction
Source§impl From<SmallBooleanFunction> for BooleanFunction
impl From<SmallBooleanFunction> for BooleanFunction
Source§fn from(v: SmallBooleanFunction) -> BooleanFunction
fn from(v: SmallBooleanFunction) -> BooleanFunction
Source§impl Mul for SmallBooleanFunction
MUL operator for Boolean functions truth tables.
impl Mul for SmallBooleanFunction
MUL operator for Boolean functions truth tables.
It is equivalent to crate::SmallBooleanFunction::bitand operator.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§impl MulAssign for SmallBooleanFunction
In-place MUL operator for Boolean functions truth tables.
impl MulAssign for SmallBooleanFunction
In-place MUL operator for Boolean functions truth tables.
It is equivalent to crate::SmallBooleanFunction::bitand_assign operator.
§Panics
If the Boolean functions have different number of variables, and the unsafe_disable_safety_checks
feature is not enabled.
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreSource§impl Not for SmallBooleanFunction
NOT operator for Boolean functions.
impl Not for SmallBooleanFunction
NOT operator for Boolean functions.
This is equivalent to the crate::BooleanFunctionImpl::reverse operation: it reverses each output of the Boolean function.
Source§impl PartialEq for SmallBooleanFunction
impl PartialEq for SmallBooleanFunction
impl Copy for SmallBooleanFunction
impl Eq for SmallBooleanFunction
impl StructuralPartialEq for SmallBooleanFunction
Auto Trait Implementations§
impl Freeze for SmallBooleanFunction
impl RefUnwindSafe for SmallBooleanFunction
impl Send for SmallBooleanFunction
impl Sync for SmallBooleanFunction
impl Unpin for SmallBooleanFunction
impl UnwindSafe for SmallBooleanFunction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more