pub struct Factoring { /* private fields */ }Expand description
The Integer Factoring problem.
Given a number to factor, find two ordered integers that multiply to give the target number. Variables represent the bits of the two factors. Factor widths may be supplied explicitly or derived from the target bit length.
§Example
use problemreductions::models::misc::Factoring;
use problemreductions::{Problem, BruteForce};
// Factor 6 using the derived 2-bit factor widths.
let problem = Factoring::new(6);
let solver = BruteForce::new();
let solutions = solver.find_all_witnesses(&problem).unwrap();
// The canonical factor order finds 2*3=6.
for (a, b) in &solutions {
assert_eq!(a * b, num_bigint::BigUint::from(6u32));
}Implementations§
Source§impl Factoring
impl Factoring
Sourcepub fn new<T: ToBigUint>(target: T) -> Self
pub fn new<T: ToBigUint>(target: T) -> Self
Create a Factoring problem with widths derived from the target.
§Arguments
target- The number to factor
Sourcepub fn with_factor_bits<T: ToBigUint>(target: T, m: usize, n: usize) -> Self
pub fn with_factor_bits<T: ToBigUint>(target: T, m: usize, n: usize) -> Self
Create a Factoring problem with explicit maximum factor widths.
The first factor is canonicalized as the smaller factor, so m must
not exceed n. Explicit widths may admit the trivial factorization
(1, target).
Sourcepub fn num_bits_first(&self) -> usize
pub fn num_bits_first(&self) -> usize
Get the maximum number of bits for the smaller factor (alias for m()).
Sourcepub fn num_bits_second(&self) -> usize
pub fn num_bits_second(&self) -> usize
Get the maximum number of bits for the larger factor (alias for n()).
Sourcepub fn target_bits(&self) -> usize
pub fn target_bits(&self) -> usize
Number of bits needed to represent the target (1 for zero).
Sourcepub fn is_valid_solution(&self, solution: &(BigUint, BigUint)) -> bool
pub fn is_valid_solution(&self, solution: &(BigUint, BigUint)) -> bool
Check if a configuration is a valid factorization.
Sourcepub fn is_valid_factorization(&self, solution: &(BigUint, BigUint)) -> bool
pub fn is_valid_factorization(&self, solution: &(BigUint, BigUint)) -> bool
Check if the configuration is a valid factorization.
Trait Implementations§
Source§impl BruteForceProblem for Factoring
impl BruteForceProblem for Factoring
Source§fn dimensions(&self) -> Vec<usize>
fn dimensions(&self) -> Vec<usize>
Source§fn num_variables(&self) -> usize
fn num_variables(&self) -> usize
impl DeclaredVariant for Factoring
Source§impl<'de> Deserialize<'de> for Factoring
impl<'de> Deserialize<'de> for Factoring
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Problem for Factoring
impl Problem for Factoring
Source§const NAME: &'static str = "Factoring"
const NAME: &'static str = "Factoring"
Source§fn parameter_names() -> &'static [&'static str]
fn parameter_names() -> &'static [&'static str]
Source§fn parameters(&self) -> ProblemParameters
fn parameters(&self) -> ProblemParameters
Source§fn evaluate(&self, solution: &Self::Solution) -> Result<Or, EvaluationError>
fn evaluate(&self, solution: &Self::Solution) -> Result<Or, EvaluationError>
Source§fn variant() -> Vec<(&'static str, &'static str)>
fn variant() -> Vec<(&'static str, &'static str)>
Source§fn problem_type() -> ProblemType
fn problem_type() -> ProblemType
Source§impl ReduceTo<CircuitSAT> for Factoring
impl ReduceTo<CircuitSAT> for Factoring
Source§fn reduce_to(&self) -> Result<Self::Result, ReductionError>
fn reduce_to(&self) -> Result<Self::Result, ReductionError>
Source§fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
Source§impl ReduceTo<ILP<i64>> for Factoring
impl ReduceTo<ILP<i64>> for Factoring
Source§fn reduce_to(&self) -> Result<Self::Result, ReductionError>
fn reduce_to(&self) -> Result<Self::Result, ReductionError>
Source§fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
Auto Trait Implementations§
impl Freeze for Factoring
impl RefUnwindSafe for Factoring
impl Send for Factoring
impl Sync for Factoring
impl Unpin for Factoring
impl UnsafeUnpin for Factoring
impl UnwindSafe for Factoring
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,
§impl<T> Conv for T
impl<T> Conv for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DynProblem for Twhere
T: Problem + Serialize + 'static,
<T as Problem>::Solution: DeserializeOwned,
<T as Problem>::Value: SolutionAggregate + Display + Serialize,
impl<T> DynProblem for Twhere
T: Problem + Serialize + 'static,
<T as Problem>::Solution: DeserializeOwned,
<T as Problem>::Value: SolutionAggregate + Display + Serialize,
Source§fn evaluate_dyn(&self, solution: &Value) -> Result<String, EvaluationError>
fn evaluate_dyn(&self, solution: &Value) -> Result<String, EvaluationError>
Source§fn evaluate_json(&self, solution: &Value) -> Result<Value, EvaluationError>
fn evaluate_json(&self, solution: &Value) -> Result<Value, EvaluationError>
Source§fn evaluate_witness_dyn(
&self,
solution: &Value,
) -> Result<Option<String>, EvaluationError>
fn evaluate_witness_dyn( &self, solution: &Value, ) -> Result<Option<String>, EvaluationError>
None when it is infeasible.
This validates feasibility, not global optimality.Source§fn serialize_json(&self) -> Value
fn serialize_json(&self) -> Value
Source§fn problem_name(&self) -> &'static str
fn problem_name(&self) -> &'static str
Problem::NAME).Source§fn parameter_names_dyn(&self) -> &'static [&'static str]
fn parameter_names_dyn(&self) -> &'static [&'static str]
Source§fn parameters_dyn(&self) -> ProblemParameters
fn parameters_dyn(&self) -> ProblemParameters
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.