Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ add_library(${MY_TARGET} STATIC
include/qboot/context.hpp
include/qboot/hor_formula.hpp
include/qboot/hor_recursion.hpp
include/qboot/my_filesystem.hpp
include/qboot/my_concepts.hpp
include/qboot/polynomial_program.hpp
include/qboot/primary_op.hpp
include/qboot/qboot.hpp
Expand All @@ -93,6 +93,9 @@ target_link_libraries(
)
if(NOT MSVC)
target_link_libraries(${MY_TARGET} INTERFACE stdc++fs)
if(NOT CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(${MY_TARGET} INTERFACE c++abi)
endif()
endif()

target_include_directories(${MY_TARGET} PUBLIC
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Some codes are taken from [cboot](https://github.com/tohtsky/cboot.git).

- [mpfr](http://mpfr.org/)

- [gcc](http://gcc.gnu.org/) (`7.4.0+`) or [clang](http://clang.llvm.org/) (`8.0.0+`)
- [gcc](http://gcc.gnu.org/) (`10.2.0+`) or [clang](http://clang.llvm.org/) (`11.0.1+`)

### Windows (MSVC)

- [mpir](https://github.com/BrianGladman/mpir.git) (You must build `lib_mpir_gc` **and** `lib_mpir_cxx`)

- [mpfr](https://github.com/BrianGladman/mpfr.git)

- [Visual Studio](https://visualstudio.microsoft.com/) (`2017+`)
- [Visual Studio](https://visualstudio.microsoft.com/) (`2019+`)

Please build `mpir` and `mpfr` in both `Debug` and `Release` mode.

Expand Down
5 changes: 3 additions & 2 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ macro(set_flags)
if(CMAKE_COMPILER_IS_GNUCXX)
set(cxx_flags ${cxx_flags} -Weffc++ -Wno-noexcept -Walloca -Wcast-align -Wcast-qual -Wconditionally-supported -Wconversion -Wctor-dtor-privacy -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-cond -Wfloat-conversion -Wfloat-equal -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wmultichar -Wmultiple-inheritance -Wnull-dereference -Wold-style-cast -Woverlength-strings -Woverloaded-virtual -Wpacked -Wredundant-decls -Wrestrict -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wsuggest-override -Wswitch-default -Wswitch-enum -Wuninitialized -Wunused-macros -Wunused-parameter -Wuseless-cast -Wvariadic-macros -Wvector-operation-performance -Wvirtual-inheritance)
else()
set(cxx_flags ${cxx_flags} -stdlib=libc++)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0.0)
set(cxx_flags ${cxx_flags} -Wno-ctad-maybe-unsupported)
endif()
set(cxx_flags ${cxx_flags} -Weverything -Wno-c++98-compat -Wno-shadow-field-in-constructor -Wno-c++98-compat-pedantic -Wno-global-constructors -Wno-exit-time-destructors -Wno-covered-switch-default)
set(cxx_flags ${cxx_flags} -Weverything -Wno-zero-as-null-pointer-constant -Wno-c++98-compat -Wno-shadow-field-in-constructor -Wno-c++98-compat-pedantic -Wno-global-constructors -Wno-exit-time-destructors -Wno-covered-switch-default)
endif()
endif()
endmacro()
Expand All @@ -43,7 +44,7 @@ function(set_default_property target dir)
DEBUG_POSTFIX "-debug"
COMPILE_OPTIONS "${cxx_flags}"
CXX_EXTENSIONS OFF
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${dir}/bin
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${dir}/bin
Expand Down
54 changes: 27 additions & 27 deletions include/qboot/algebra/complex_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ namespace qboot::algebra
// \sum_{n = 0}^{lambda / 2} \sum_{m = 0}^{lambda - 2 n} this->at(n, m) (x - x0) ^ m (y - y0) ^ n + ...
// we take (x0, y0) = (1 / 2, 0)
// if a nontrivial symmetry even (resp. odd) is given, m runs over even (resp. odd) number only.
// Ring must be mp::real or Polynomial
template <class Ring>
// R must be mp::real or Polynomial
template <Ring R>
class ComplexFunction
{
template <class Ring2>
template <Ring R2>
friend class ComplexFunction;
FunctionSymmetry sym_ = FunctionSymmetry::Mixed;
uint32_t lambda_;
Vector<Ring> coeffs_;
Vector<R> coeffs_;
// indices are aligned by lexicographical order of (dy, dx)
// i.e., (dx, dy) is the index(dx, dy)-th element in
// [(dx, dy) for dy in range(lambda // 2) for dx in range(lambda - 2 * dy) if sym is Mixed or dx % 2 == sym]
Expand All @@ -79,7 +79,7 @@ namespace qboot::algebra
default: return (lambda_ + 2 - dy) * dy + dx;
}
}
ComplexFunction(Vector<Ring>&& v, uint32_t l, FunctionSymmetry sym)
ComplexFunction(Vector<R>&& v, uint32_t l, FunctionSymmetry sym)
: sym_(sym), lambda_(l), coeffs_(std::move(v))
{
}
Expand Down Expand Up @@ -112,9 +112,9 @@ namespace qboot::algebra
// get coefficient of the term (x - x0) ^ {dx} (y - y0) ^ {dy}
// 0 <= dx, dy and dx + 2 dy <= lambda
// if symmetry is even or odd, the parity of dx must equals symmetry
[[nodiscard]] Ring& at(uint32_t dx, uint32_t dy) & { return coeffs_[index(dx, dy)]; }
[[nodiscard]] const Ring& at(uint32_t dx, uint32_t dy) const& { return coeffs_[index(dx, dy)]; }
[[nodiscard]] Vector<Ring> flatten() && { return std::move(coeffs_); }
[[nodiscard]] R& at(uint32_t dx, uint32_t dy) & { return coeffs_[index(dx, dy)]; }
[[nodiscard]] const R& at(uint32_t dx, uint32_t dy) const& { return coeffs_[index(dx, dy)]; }
[[nodiscard]] Vector<R> flatten() && { return std::move(coeffs_); }

[[nodiscard]] auto abs() const { return coeffs_.abs(); }
[[nodiscard]] auto norm() const { return coeffs_.norm(); }
Expand Down Expand Up @@ -144,14 +144,14 @@ namespace qboot::algebra
coeffs_ -= f.coeffs_;
return *this;
}
template <class T>
ComplexFunction& operator*=(const T& r) &
template <class S>
ComplexFunction& operator*=(const S& r) &
{
coeffs_ *= r;
return *this;
}
template <class T>
ComplexFunction& operator/=(const T& r) &
template <class S>
ComplexFunction& operator/=(const S& r) &
{
coeffs_ /= r;
return *this;
Expand Down Expand Up @@ -204,23 +204,23 @@ namespace qboot::algebra
}
return z;
}
template <class R>
friend ComplexFunction mul_scalar(const R& r, const ComplexFunction& x)
template <class S>
friend ComplexFunction mul_scalar(const S& r, const ComplexFunction& x)
{
return ComplexFunction(mul_scalar(r, x.coeffs_), x.lambda_, x.sym_);
}
template <class R>
friend ComplexFunction mul_scalar(const R& r, ComplexFunction&& x)
template <class S>
friend ComplexFunction mul_scalar(const S& r, ComplexFunction&& x)
{
return std::move(x *= r);
}
template <class R>
friend ComplexFunction operator/(const ComplexFunction& x, const R& r)
template <class S>
friend ComplexFunction operator/(const ComplexFunction& x, const S& r)
{
return ComplexFunction(x.coeffs_ / r, x.lambda_, x.sym_);
}
template <class R>
friend ComplexFunction operator/(ComplexFunction&& x, const R& r)
template <class S>
friend ComplexFunction operator/(ComplexFunction&& x, const S& r)
{
return std::move(x /= r);
}
Expand All @@ -229,22 +229,22 @@ namespace qboot::algebra
return x.lambda_ == y.lambda_ && x.sym_ == y.sym_ && x.coeffs_ == y.coeffs_;
}
friend bool operator!=(const ComplexFunction& x, const ComplexFunction& y) { return !(x == y); }
[[nodiscard]] ComplexFunction<_evaluated_t<Ring>> eval(const mp::real& x) const
[[nodiscard]] ComplexFunction<_evaluated_t<R>> eval(const mp::real& x) const
{
return ComplexFunction<_evaluated_t<Ring>>(coeffs_.eval(x), lambda_, sym_);
return ComplexFunction<_evaluated_t<R>>(coeffs_.eval(x), lambda_, sym_);
}
};
template <>
ComplexFunction<mp::real> ComplexFunction<mp::real>::proj(FunctionSymmetry sym) &&;
template <>
ComplexFunction<Polynomial> ComplexFunction<Polynomial>::proj(FunctionSymmetry sym) &&;
template <class Ring>
ComplexFunction<_polynomialize_t<Ring>> to_pol(Vector<ComplexFunction<Ring>>* coeffs)
template <Ring R>
ComplexFunction<_polynomialize_t<R>> to_pol(Vector<ComplexFunction<R>>* coeffs)
{
uint32_t lambda = coeffs->at(0).lambda(), len = coeffs->size();
auto sym = coeffs->at(0).symmetry();
ComplexFunction<_polynomialize_t<Ring>> ans(lambda, sym);
Vector<Ring> v(len);
ComplexFunction<_polynomialize_t<R>> ans(lambda, sym);
Vector<R> v(len);
for (uint32_t dy = 0; dy <= lambda / 2; ++dy)
for (uint32_t dx = 0; dx + 2 * dy <= lambda; ++dx)
if (_matches(sym, dx))
Expand All @@ -254,7 +254,7 @@ namespace qboot::algebra
}
return ans;
}
template <class R>
template <Ring R>
std::ostream& operator<<(std::ostream& out, const ComplexFunction<R>& v)
{
out << "[";
Expand Down
Loading