pfor/src/pfor/lineardiophantineequation.h

71 lines
2.2 KiB
C++

#ifndef PFOR_PFOR_LINEARDIOPHANTINEEQUATION_H
#define PFOR_PFOR_LINEARDIOPHANTINEEQUATION_H
#include "expression/operandtag.h"
#include "index/property/linear.h"
#include "index/traits.h"
#include "mp/meta.h"
#include "mp/pack.h"
namespace pfor {
/**
*/
template<index::Value a, index::Value b, index::Value c>
constexpr bool hasLinearDiophantineSolution = ((c % gcd(a, b)) == 0);
template<index::Value c>
constexpr bool hasLinearDiophantineSolution<0, 0, c> = false;
/**
*/
template<typename, typename> struct NoLinearDiophantineSolution;
template<typename Index>
struct NoLinearDiophantineSolution<Index, Index>: std::true_type {};
template<typename Index0, typename Index1>
struct NoLinearDiophantineSolution {
static constexpr index::Value a = index::linearSlope<Index0>;
static constexpr index::Value b = -index::linearSlope<Index1>;
static constexpr index::Value c = index::linearOffset<Index0>-index::linearOffset<Index1>;
static constexpr bool value = not hasLinearDiophantineSolution<a, b, c>;
};
template<typename A, typename B>
constexpr bool noLinearDiophantineSolution = NoLinearDiophantineSolution<A, B>::value;
/**
*/
template<typename, typename> struct NoLinearDiophantineSolutionForVec;
template<typename W, typename H, typename... Ps>
struct NoLinearDiophantineSolutionForVec<W, Pack<H, Ps...>> {
static constexpr bool value = noLinearDiophantineSolution<W, H> && NoLinearDiophantineSolutionForVec<W, Pack<Ps...>>::value;
};
template<typename W>
struct NoLinearDiophantineSolutionForVec<W, Pack<>>: std::true_type {};
template<typename W, typename P>
constexpr bool noLinearDiophantineSolutionForVec = NoLinearDiophantineSolutionForVec<W, P>::value;
/**
*/
template<typename, typename> struct NoLinearDiophantineSolutionForGrid;
template<typename H, typename... Ws, typename P>
struct NoLinearDiophantineSolutionForGrid<Pack<H, Ws...>, P> {
static constexpr bool value = noLinearDiophantineSolutionForVec<H, P> && NoLinearDiophantineSolutionForGrid<Pack<Ws...>, P>::value;
};
template<typename P>
struct NoLinearDiophantineSolutionForGrid<Pack<>, P>: std::true_type {};
template<typename W, typename P>
constexpr bool noLinearDiophantineSolutionForGrid = NoLinearDiophantineSolutionForGrid<W, P>::value;
}
#endif