Functions to help treat a particular linear diophantine equation. More...
Functions | |
bool | has_solution (const std::vector< unsigned > &a, int b) |
Checks whether a diophantine has a solution. More... | |
bool | next_solution (std::vector< unsigned > &x, const std::vector< unsigned > &a, int b) |
Finds the next solution of the diophantine equation, if it exists. More... | |
bool | first_solution (std::vector< unsigned > &x, const std::vector< unsigned > &a, int b) |
Finds the first solution of the diophantine equation, if it exists. More... | |
Functions to help treat a particular linear diophantine equation.
Here we want to treat a special case of the linear diophantine equation \(\sum_i a_i x_i = b\) with \(a_i > 0\) and \(x_i >= 0\).
bool Scine::Molassembler::Shapes::Diophantine::first_solution | ( | std::vector< unsigned > & | x, |
const std::vector< unsigned > & | a, | ||
int | b | ||
) |
Finds the first solution of the diophantine equation, if it exists.
Finds the first solution of the linear diophantine \(\sum_i a_ix_i = b\) with positive \(a_i\), non-negative \(x_i\) and positive \(b\).
Use the following pattern:
a
!
See https://arxiv.org/pdf/math/0010134.pdf for a sketch on how this could be properly solved.x | Vector to store the first solution into (resize and fill is handled by this function) |
a | The constant coefficients, strictly descending (no duplicate values) and non-zero. |
b | The sought inner product result |
bool Scine::Molassembler::Shapes::Diophantine::has_solution | ( | const std::vector< unsigned > & | a, |
int | b | ||
) |
Checks whether a diophantine has a solution.
a | The constant coefficients, in no particular order and without value constraints. The list may not be empty, though. |
b | The sought inner product result. |
gcd(a_1, ..., a_n)
is a divisor of b. If so, the diophantine has a solution. bool Scine::Molassembler::Shapes::Diophantine::next_solution | ( | std::vector< unsigned > & | x, |
const std::vector< unsigned > & | a, | ||
int | b | ||
) |
Finds the next solution of the diophantine equation, if it exists.
Finds the next solution of the linear diophantine \(\sum_i a_ix_i = b\) with positive \(a_i\), non-negative \(x_i\) and positive \(b\).
Use the following pattern:
a
! See https://arxiv.org/pdf/math/0010134.pdf for a sketch on how this could be properly solved.x | Filled coefficient vector of equal size as a, whose values represent a solution to the diophantine (i.e. inner_product(a, x) == b ) |
a | The constant coefficients, strictly descending (no duplicate values) and non-zero. |
b | The sought inner product result |