Skip to content

Commit

Permalink
Put factorization for fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Nov 20, 2023
1 parent 245d095 commit ee626a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src_number/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#PROGRAM = TestSquareRoot test_unordered_map_mpzq Factorize PracticalInf TestQuoInt PrintStaticInfo RealCubicFieldTest QuadFieldTest RationalTest TestTypeBoostGmp TestGetBit TestQuadraticResidue
PROGRAM = TestSquareRoot test_unordered_map_mpzq Factorize PracticalInf TestQuoInt PrintStaticInfo RealCubicFieldTest QuadFieldTest RationalTest TestTypeBoostGmp TestGetBit TestQuadraticResidue
#PROGRAM = test_mpz_givaro
#PROGRAM = test_unordered_map_mpzq
#PROGRAM = Factorize
Expand All @@ -11,7 +11,7 @@
#PROGRAM = RealCubicFieldTest
#PROGRAM = RationalTest
#PROGRAM = TestTypeBoostGmp
PROGRAM = TestQuadraticResidue
#PROGRAM = TestQuadraticResidue

OBJECTS = $(PROGRAM:%=%.o)

Expand Down
25 changes: 21 additions & 4 deletions src_number/factorizations.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ template <typename T> bool IsPrime(const T &N) {
}
}

template <typename T> std::vector<T> FactorsInt(T const &N) {
template <typename T> std::vector<T> Kernel_FactorsInt(T const &N) {
static_assert(is_implementation_of_Z<T>::value, "Requires T to be a Z ring");
if (N == 1)
return {};
Expand All @@ -95,8 +95,27 @@ template <typename T> std::vector<T> FactorsInt(T const &N) {
}
}

template <typename T>
inline typename std::enable_if<is_implementation_of_Z<T>::value,std::vector<T>>::type
FactorsInt(T const &N) {
return Kernel_FactorsInt(N);
}

template <typename T>
inline typename std::enable_if<!is_implementation_of_Z<T>::value,std::vector<T>>::type
FactorsInt(T const &N) {
using Tint = typename underlying_ring<T>::ring_type;
Tint N_int = UniversalScalarConversion<Tint,T>(N);
std::vector<Tint> LFact_int = Kernel_FactorsInt(N_int);
std::vector<T> LFact;
for (auto & val_i : LFact_int) {
T val = UniversalScalarConversion<T,Tint>(val_i);
LFact.push_back(val);
}
return LFact;
}

template <typename T> std::map<T, size_t> FactorsIntMap(T const &N) {
static_assert(is_implementation_of_Z<T>::value, "Requires T to be a Z ring");
std::vector<T> vect = FactorsInt(N);
std::map<T, size_t> map;
for (auto &eV : vect) {
Expand All @@ -107,7 +126,6 @@ template <typename T> std::map<T, size_t> FactorsIntMap(T const &N) {

template <typename T>
std::vector<T> GetAllFactors(std::map<T, int> const &eMap) {
static_assert(is_implementation_of_Z<T>::value, "Requires T to be a Z ring");
std::vector<T> LVal = {1};
for (auto &kv : eMap) {
std::vector<T> NewVal;
Expand All @@ -124,7 +142,6 @@ std::vector<T> GetAllFactors(std::map<T, int> const &eMap) {
}

template <typename T> std::vector<T> GetAllFactors(T const &N) {
static_assert(is_implementation_of_Z<T>::value, "Requires T to be a Z ring");
std::vector<T> LFact = FactorsInt(N);
std::map<T, int> eMap;
for (auto &eVal : LFact)
Expand Down

0 comments on commit ee626a7

Please sign in to comment.