diff --git a/src_basic/Basic_functions.h b/src_basic/Basic_functions.h index 455c574..4f09b53 100644 --- a/src_basic/Basic_functions.h +++ b/src_basic/Basic_functions.h @@ -68,6 +68,13 @@ template T T_abs(T const &eVal) { return fVal; } +template T T_sign(T const &eVal) { + T fVal(1); + if (eVal < 0) + fVal = T(-1); + return fVal; +} + // use std::min for generic types (int, long, float, ...) template T T_min(T const &eVal1, T const &eVal2) { if (eVal1 > eVal2) diff --git a/src_matrix/MAT_Matrix.h b/src_matrix/MAT_Matrix.h index a2ab7a9..d9c478a 100644 --- a/src_matrix/MAT_Matrix.h +++ b/src_matrix/MAT_Matrix.h @@ -2766,6 +2766,22 @@ template MyVector SignCanonicalizeVector(const MyVector &V) { throw TerminalException{1}; } +template +MyVector GetDiagonal(MyMatrix const& M) { + int n_col = M.cols(); + int n_row = M.rows(); + if (n_row != n_col) { + std::cerr << "The matrix is rectangular but not square, so diagonal is not defined\n"; + throw TerminalException{1}; + } + MyMatrix V(n_row); + for (int i=0; i(TheMod); process(TheMod); // process(TheMod); diff --git a/src_number/factorizations.h b/src_number/factorizations.h index 7f3cba1..5fef6fb 100644 --- a/src_number/factorizations.h +++ b/src_number/factorizations.h @@ -95,6 +95,18 @@ template std::vector FactorsInt(T const &N) { } } +template std::map FactorsIntMap(T const &N) { + static_assert(is_implementation_of_Z::value, "Requires T to be a Z ring"); + std::vector vect = FactorsInt(N); + std::map map; + for (auto & eV : vect) { + map[eV] += 1; + } + return map; +} + + + template std::vector GetAllFactors(std::map const &eMap) { static_assert(is_implementation_of_Z::value, "Requires T to be a Z ring"); diff --git a/src_number/quadratic_residue.h b/src_number/quadratic_residue.h index fb4b0d7..2b53060 100644 --- a/src_number/quadratic_residue.h +++ b/src_number/quadratic_residue.h @@ -9,6 +9,7 @@ #include // clang-format on +// This is an exhaustive search that works even if m is not prime. template std::optional find_quadratic_residue(T const& a, T const& m_in) { static_assert(is_implementation_of_Z::value, "Requires T to be a Z ring"); @@ -26,11 +27,8 @@ std::optional find_quadratic_residue(T const& a, T const& m_in) { T x(0); T TwoXpOne(1); T xSqr(0); - // std::cerr << "m=" << m << " a=" << a << " a_mod=" << a_mod << "\n"; while (x != upper) { - // std::cerr << " x=" << x << " xSqr=" << xSqr << "\n"; if (xSqr == a_mod) { - // std::cerr << "Returning x=" << x << "\n"; return x; } xSqr += TwoXpOne;