From ca4a7ed4257411c9f4974c6aef406e0427f3ab69 Mon Sep 17 00:00:00 2001 From: sushant Date: Tue, 29 Jul 2014 14:39:48 +0530 Subject: [PATCH 01/21] Adding Arb in CMakeList. Arb can be used -DWITH_ARB=yes --- CMakeLists.txt | 17 +++++++++++++++++ cmake/FindARB.cmake | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 cmake/FindARB.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8217e54dcf..9a31e73984 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,17 @@ if (WITH_PRIMESIEVE) set(HAVE_CSYMPY_PRIMESIEVE yes) endif() +#ARB +set(WITH_ARB no + CACHE BOOL "Build with Arb") + +if (WITH_ARB) + find_package(ARB REQUIRED) + include_directories(${ARB_INCLUDE_DIRS}) + set(LIBS ${LIBS} ${ARB_LIBRARY}) + set(HAVE_CSYMPY_ARB yes) +endif() + # Python set(WITH_PYTHON no CACHE BOOL "Build with Python wrappers") @@ -171,5 +182,11 @@ if (WITH_PRIMESIEVE) message("PRIMESIEVE_LIBRARIES: ${PRIMESIEVE_LIBRARY}") endif() +message("WITH_ARB: ${WITH_ARB}") +if (WITH_ARB) + message("ARB_INCLUDE_DIRS: ${ARB_INCLUDE_DIRS}") + message("ARB_LIBRARIES: ${ARB_LIBRARY}") +endif() + message("Copying source of python wrappers into: ${CMAKE_CURRENT_BINARY_DIR}") file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/csympy DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/cmake/FindARB.cmake b/cmake/FindARB.cmake new file mode 100644 index 0000000000..1db7c106e3 --- /dev/null +++ b/cmake/FindARB.cmake @@ -0,0 +1,9 @@ +find_path(ARB_INCLUDE_DIR fmprb.h $ENV{PYTHONHPC}/include) +find_library(ARB arb $ENV{PYTHONHPC}/lib) +set(ARB_LIBRARY ${ARB}) +set(ARB_INCLUDE_DIRS ${ARB_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(ARB DEFAULT_MSG ARB_LIBRARY ARB_INCLUDE_DIR) + +mark_as_advanced(ARB_INCLUDE_DIR ARB) \ No newline at end of file From 926d8a05ad6a3ff694f26ee933922e3da78029c0 Mon Sep 17 00:00:00 2001 From: sushant Date: Tue, 29 Jul 2014 17:45:47 +0530 Subject: [PATCH 02/21] Modified Travis to install ARB if WITH_ARB is set Also updated bin/test_travis.sh Fix comment message --- .travis.yml | 13 +++++++++++++ bin/test_travis.sh | 3 +++ 2 files changed, 16 insertions(+) diff --git a/.travis.yml b/.travis.yml index f7a706a0dc..ea4e28447b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,8 @@ env: - BUILD_TYPE="Debug" WITH_BFD="yes" WITH_CSYMPY_ASSERT="yes" WITH_PRIMESIEVE="yes" # Debug build (with BFD and CSYMPY_ASSERT) with Python 2.7 - BUILD_TYPE="Debug" WITH_BFD="yes" WITH_CSYMPY_ASSERT="yes" WITH_PYTHON="yes" + # Debug build (with BFD and CSYMPY_ASSERT) with Arb + - BUILD_TYPE="Debug" WITH_BFD="yes" WITH_CSYMPY_ASSERT="yes" WITH_ARB="yes" # Debug build with Teuchos::RCP (just to test that it compiles) - BUILD_TYPE="Debug" WITH_BFD="yes" WITH_CSYMPY_RCP="no" # Release build (with BFD) @@ -79,6 +81,17 @@ before_install: tar -xzvf primesieve-5.2.tar.gz; cd primesieve-5.2 && ./configure && make && sudo make install && cd ..; fi + - if [[ "${WITH_ARB}" == "yes" ]]; then + wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.gz; + tar -xzvf mpfr-3.1.2.tar.gz; + cd mpfr-3.1.2 && ./configure && make && sudo make install && cd ..; + wget http://www.flintlib.org/flint-2.4.4.tar.gz; + tar -xzvf flint-2.4.4.tar.gz; + cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; + wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; + tar -xzvf 2.1.0.tar.gz; + cd arb-2.1.0 && ./configure && make && sudo make install && cd ..; + fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then pip install cython sympy --use-mirrors; diff --git a/bin/test_travis.sh b/bin/test_travis.sh index e7e3686c19..666350d262 100755 --- a/bin/test_travis.sh +++ b/bin/test_travis.sh @@ -46,6 +46,9 @@ fi if [[ "${WITH_PRIMESIEVE}" != "" ]]; then cmake_line="$cmake_line -DWITH_PRIMESIEVE=${WITH_PRIMESIEVE}" fi +if [[ "${WITH_ARB}" != "" ]]; then + cmake_line="$cmake_line -DWITH_ARB=${WITH_ARB}" +fi if [[ "${PYTHON_INSTALL}" == "yes" ]]; then git clean -dfx python setup.py install From 395e8bc81bd7aa6c71a8371211d02dce58b45fed Mon Sep 17 00:00:00 2001 From: sushant Date: Tue, 29 Jul 2014 19:10:12 +0530 Subject: [PATCH 03/21] Update mpfr install command in .travis.yml The updated command is: sudo apt-get install libmpfr-dev --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea4e28447b..c6981a15b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,9 +82,7 @@ before_install: cd primesieve-5.2 && ./configure && make && sudo make install && cd ..; fi - if [[ "${WITH_ARB}" == "yes" ]]; then - wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.gz; - tar -xzvf mpfr-3.1.2.tar.gz; - cd mpfr-3.1.2 && ./configure && make && sudo make install && cd ..; + sudo apt-get install libmpfr-dev; wget http://www.flintlib.org/flint-2.4.4.tar.gz; tar -xzvf flint-2.4.4.tar.gz; cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; From 091c82caa59b0827f0b553d537e04ad436de70c1 Mon Sep 17 00:00:00 2001 From: sushant Date: Wed, 30 Jul 2014 12:14:17 +0530 Subject: [PATCH 04/21] Added explicit path for gmp --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c6981a15b8..5671f4dd64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ before_install: cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; tar -xzvf 2.1.0.tar.gz; - cd arb-2.1.0 && ./configure && make && sudo make install && cd ..; + cd arb-2.1.0 && ./configure --with-gmp=/usr && make && sudo make install && cd ..; fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then From 6b87a94ed32ccf1c6079e9f3a52be1026b9d87d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 30 Jul 2014 09:10:20 -0600 Subject: [PATCH 05/21] Travis: remove "-v" from tar calls --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5671f4dd64..287e3d8126 100644 --- a/.travis.yml +++ b/.travis.yml @@ -84,10 +84,10 @@ before_install: - if [[ "${WITH_ARB}" == "yes" ]]; then sudo apt-get install libmpfr-dev; wget http://www.flintlib.org/flint-2.4.4.tar.gz; - tar -xzvf flint-2.4.4.tar.gz; + tar -xzf flint-2.4.4.tar.gz; cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; - tar -xzvf 2.1.0.tar.gz; + tar -xzf 2.1.0.tar.gz; cd arb-2.1.0 && ./configure --with-gmp=/usr && make && sudo make install && cd ..; fi install: From 37c99d79852efb00b802575810894d6e200d336b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 30 Jul 2014 09:11:59 -0600 Subject: [PATCH 06/21] Remove the --with-gmp --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 287e3d8126..8f32730304 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ before_install: cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; tar -xzf 2.1.0.tar.gz; - cd arb-2.1.0 && ./configure --with-gmp=/usr && make && sudo make install && cd ..; + cd arb-2.1.0 && ./configure && make && sudo make install && cd ..; fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then From 1fa88f761f6dcc88a79b3451a2005365d4372467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 30 Jul 2014 09:12:16 -0600 Subject: [PATCH 07/21] Specify the location of libgmp.so --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8f32730304..767fb209da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ before_install: cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; tar -xzf 2.1.0.tar.gz; - cd arb-2.1.0 && ./configure && make && sudo make install && cd ..; + cd arb-2.1.0 && ./configure && make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu/ && sudo make install && cd ..; fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then From aef0e46ed34a75d6dfe622a60132e12aefddd2f1 Mon Sep 17 00:00:00 2001 From: sushant Date: Wed, 30 Jul 2014 20:42:44 +0530 Subject: [PATCH 08/21] Installing Arb as an extension of flint Also removed -v flags to supress output in untar --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5671f4dd64..35bd3128af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,17 +78,16 @@ before_install: fi - if [[ "${WITH_PRIMESIEVE}" == "yes" ]]; then wget http://dl.bintray.com/kimwalisch/primesieve/primesieve-5.2.tar.gz; - tar -xzvf primesieve-5.2.tar.gz; + tar -xzf primesieve-5.2.tar.gz; cd primesieve-5.2 && ./configure && make && sudo make install && cd ..; fi - if [[ "${WITH_ARB}" == "yes" ]]; then sudo apt-get install libmpfr-dev; - wget http://www.flintlib.org/flint-2.4.4.tar.gz; - tar -xzvf flint-2.4.4.tar.gz; - cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; - tar -xzvf 2.1.0.tar.gz; - cd arb-2.1.0 && ./configure --with-gmp=/usr && make && sudo make install && cd ..; + tar -xzf 2.1.0.tar.gz; + wget http://www.flintlib.org/flint-2.4.4.tar.gz; + tar -xzf flint-2.4.4.tar.gz; + cd flint-2.4.4 && ./configure --extensions=../arb-2.1.0 && make && sudo make install && cd ..; fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then From f89f148712ef90dd84f4fc75c39fb5e539d9e595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 30 Jul 2014 09:46:31 -0600 Subject: [PATCH 09/21] Arb: specify MPFR library location --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 767fb209da..9eb4c7c522 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ before_install: cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; tar -xzf 2.1.0.tar.gz; - cd arb-2.1.0 && ./configure && make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu/ && sudo make install && cd ..; + cd arb-2.1.0 && ./configure && make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu && sudo make install && cd ..; fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then From 7538f1798fc93ff090c97a07cc8c4f64ff2b0ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 30 Jul 2014 11:16:04 -0600 Subject: [PATCH 10/21] Arb: give the GMP paths to "make install" Thanks to Isuru Fernando (@isuruf) for spotting this. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9eb4c7c522..c105f40e1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ before_install: cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; tar -xzf 2.1.0.tar.gz; - cd arb-2.1.0 && ./configure && make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu && sudo make install && cd ..; + cd arb-2.1.0 && ./configure && make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu && sudo make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu install && cd ..; fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then From 5b08d65746cdb07668183be205b45a7367f70486 Mon Sep 17 00:00:00 2001 From: sushant Date: Fri, 1 Aug 2014 13:37:37 +0530 Subject: [PATCH 11/21] Adding include flags for arb in CMAKE This is perhaps not the best way, but works for me @certik will review this once he is back from vacation --- CMakeLists.txt | 6 +++--- src/csympy_config.h.in | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a31e73984..9775479c61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,14 +19,14 @@ endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb") + "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb -I/usr/local/include/flint ") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-parameter") endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb") + "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb -I/usr/local/include/flint") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-parameter") endif() @@ -65,7 +65,7 @@ set(WITH_ARB no if (WITH_ARB) find_package(ARB REQUIRED) include_directories(${ARB_INCLUDE_DIRS}) - set(LIBS ${LIBS} ${ARB_LIBRARY}) + set(LIBS ${LIBS} ${ARB_LIBRARY} -lflint -larb) set(HAVE_CSYMPY_ARB yes) endif() diff --git a/src/csympy_config.h.in b/src/csympy_config.h.in index 423a580824..609b995de3 100644 --- a/src/csympy_config.h.in +++ b/src/csympy_config.h.in @@ -12,3 +12,6 @@ /* Define if you want to enable PRIMESIEVE support in CSymPy */ #cmakedefine HAVE_CSYMPY_PRIMESIEVE + +/* Define if you want to enable ARB support in CSymPy */ +#cmakedefine HAVE_CSYMPY_ARB From 4c1c283abc160e553e936caf8e35250172ae855e Mon Sep 17 00:00:00 2001 From: sushant Date: Fri, 1 Aug 2014 13:44:42 +0530 Subject: [PATCH 12/21] Added `bernoulli` function * Linked fmpq_t and mpq_class * Added tests. --- src/ntheory.cpp | 22 ++++++++++++++++++++++ src/ntheory.h | 2 ++ src/tests/ntheory/test_ntheory.cpp | 11 +++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/ntheory.cpp b/src/ntheory.cpp index bfd3005b7b..9f38280608 100644 --- a/src/ntheory.cpp +++ b/src/ntheory.cpp @@ -9,6 +9,11 @@ #ifdef HAVE_CSYMPY_PRIMESIEVE # include #endif // HAVE_CSYMPY_PRIMESIEVE +#ifdef HAVE_CSYMPY_ARB +# include "arb.h" +# include "bernoulli.h" +# include "rational.h" +#endif // HAVE_CSYMPY_ARB #include "dict.h" namespace CSymPy { @@ -498,5 +503,22 @@ void prime_factor_multiplicities(const RCP &n, insert(primes_mul, integer(_n), 1); } +RCP bernoulli(ulong n) +{ +#ifdef HAVE_CSYMPY_ARB + fmpq_t res; + fmpq_init(res); + bernoulli_fmpq_ui(res, n); + mpq_t a; + mpq_init(a); + fmpq_get_mpq(a, res); + mpq_class b (a); + fmpq_clear(res); + mpq_clear(a); + return Rational::from_mpq(b); +#else + throw std::runtime_error("Currently supported only if ARB is installed"); +#endif +} } // CSymPy diff --git a/src/ntheory.h b/src/ntheory.h index c8de4dd54f..2813afcff5 100644 --- a/src/ntheory.h +++ b/src/ntheory.h @@ -90,6 +90,8 @@ void prime_factors(const RCP &n, void prime_factor_multiplicities(const RCP &n, map_integer_uint &primes); +//! Computes the Bernoulli number Bn as an exact fraction, for an isolated integer n +RCP bernoulli(ulong n); } #endif diff --git a/src/tests/ntheory/test_ntheory.cpp b/src/tests/ntheory/test_ntheory.cpp index b0b1560d39..67337fb42a 100644 --- a/src/tests/ntheory/test_ntheory.cpp +++ b/src/tests/ntheory/test_ntheory.cpp @@ -19,6 +19,7 @@ using CSymPy::rcp_dynamic_cast; using CSymPy::mod_inverse; using CSymPy::mod; using CSymPy::Number; +using CSymPy::bernoulli; void test_gcd_lcm() { @@ -352,6 +353,15 @@ void test_prime_factor_multiplicities() _test_prime_factor_multiplicities(i2357); } +void test_bernoulli() +{ + RCP res; + #ifdef HAVE_CSYMPY_ARB + res = bernoulli(12); + std::cout << *res << std::endl; + #endif +} + int main(int argc, char* argv[]) { print_stack_on_segfault(); @@ -371,6 +381,7 @@ int main(int argc, char* argv[]) test_prime_factors(); test_prime_factor_multiplicities(); test_modulo(); + test_bernoulli(); return 0; } From b30e6a060dae91043bf6a6d2ad876e69168490a2 Mon Sep 17 00:00:00 2001 From: sushant Date: Fri, 1 Aug 2014 20:25:23 +0530 Subject: [PATCH 13/21] Uodated bernoulli test to check exception if ARB is not present --- src/tests/ntheory/test_ntheory.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tests/ntheory/test_ntheory.cpp b/src/tests/ntheory/test_ntheory.cpp index 67337fb42a..7267cf71d0 100644 --- a/src/tests/ntheory/test_ntheory.cpp +++ b/src/tests/ntheory/test_ntheory.cpp @@ -2,11 +2,13 @@ #include "ntheory.h" #include "integer.h" +#include "rational.h" #include "add.h" #include "mul.h" #include "dict.h" using CSymPy::Integer; +using CSymPy::Rational; using CSymPy::print_stack_on_segfault; using CSymPy::RCP; using CSymPy::fibonacci; @@ -355,10 +357,14 @@ void test_prime_factor_multiplicities() void test_bernoulli() { - RCP res; + RCP r1; + RCP r2; #ifdef HAVE_CSYMPY_ARB - res = bernoulli(12); - std::cout << *res << std::endl; + r1 = bernoulli(12); + r2 = Rational::from_two_ints(integer(-691), integer(2730)); + assert(eq(r1, r2)); + #else + CSYMPY_CHECK_THROW(bernoulli(12), std::runtime_error) #endif } From bbc895ddc0c039fa7088f78cc25eecc5db11019a Mon Sep 17 00:00:00 2001 From: sushant Date: Fri, 1 Aug 2014 21:06:32 +0530 Subject: [PATCH 14/21] Upgraded ARB from 2.1.0 to 2.2.0 This should fix issues in travis builds --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd1a5e97fe..b9d9d6dc21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,9 +86,9 @@ before_install: wget http://www.flintlib.org/flint-2.4.4.tar.gz; tar -xzf flint-2.4.4.tar.gz; cd flint-2.4.4 && ./configure && make && sudo make install && cd ..; - wget https://github.com/fredrik-johansson/arb/archive/2.1.0.tar.gz; - tar -xzf 2.1.0.tar.gz; - cd arb-2.1.0 && ./configure && make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu && sudo make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu install && cd ..; + wget https://github.com/fredrik-johansson/arb/archive/2.2.0.tar.gz; + tar -xzf 2.2.0.tar.gz; + cd arb-2.2.0 && ./configure && make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu && sudo make ARB_GMP_LIB_DIR=/usr/lib/x86_64-linux-gnu ARB_MPFR_LIB_DIR=/usr/lib/x86_64-linux-gnu install && cd ..; fi install: - if [[ "${WITH_PYTHON}" == "yes" ]]; then From 89daf752eace796bf9c9ed4dfa5fa22e7b87ecb7 Mon Sep 17 00:00:00 2001 From: sushant Date: Fri, 1 Aug 2014 21:42:08 +0530 Subject: [PATCH 15/21] Updated `bin/test_travis.sh` to link installed libraries for arb --- bin/test_travis.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/test_travis.sh b/bin/test_travis.sh index 666350d262..d8466a596a 100755 --- a/bin/test_travis.sh +++ b/bin/test_travis.sh @@ -88,6 +88,9 @@ else if [[ "${WITH_PRIMESIEVE}" != "" ]]; then extra_libs="$extra_libs -lprimesieve" fi + if [[ "${WITH_ARB}" != "" ]]; then + extra_libs="$extra_libs -larb -lflint" + fi g++ -std=c++0x -I$our_install_dir/include/ -L$our_install_dir/lib test_basic.cpp -lcsympy -lgmpxx -lgmp -lteuchos $extra_libs ./a.out fi From fc05ecb023bf5c49d5a32b4f52c938c0abf92e77 Mon Sep 17 00:00:00 2001 From: sushant Date: Sat, 2 Aug 2014 13:38:31 +0530 Subject: [PATCH 16/21] Added `Zeta` class * Added the basic API * Added the function definitions --- src/functions.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++ src/functions.h | 46 +++++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/src/functions.cpp b/src/functions.cpp index cb472d0d98..b38165bbe0 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -2134,4 +2134,89 @@ RCP ACoth::create(const RCP &arg) const { return acoth(arg); } + +Zeta::Zeta(const RCP &s, const RCP &a) + : s_{s}, a_{a} +{ + CSYMPY_ASSERT(is_canonical(s_, a_)) +} + +Zeta::Zeta(const RCP &s) + : s_{s}, a_{one} +{ + CSYMPY_ASSERT(is_canonical(s_, a_)) +} + +bool Zeta::is_canonical(const RCP &s, const RCP &a) +{ + if (eq(s, zero)) return false; + if (eq(s, one)) return false; + return true; +} + +std::size_t Zeta::__hash__() const +{ + std::size_t seed = 0; + hash_combine(seed, *s_); + hash_combine(seed, *a_); + return seed; +} + +bool Zeta::__eq__(const Basic &o) const +{ + if (is_a(o) && + eq(s_, static_cast(o).s_) && + eq(a_, static_cast(o).a_)) + return true; + return false; +} + +int Zeta::compare(const Basic &o) const +{ + CSYMPY_ASSERT(is_a(o)) + return s_->__cmp__(*(static_cast(o).s_)); +} + + +std::string Zeta::__str__() const +{ + std::ostringstream o; + o << "zeta(" << *s_ ; + if (neq(a_, one)) + o << ", " << *a_; + o << ")"; + return o.str(); +} + +RCP Zeta::diff(const RCP &x) const +{ + // TODO: check if it is differentiated wrt s + return mul(mul(mul(minus_one, s_), zeta(add(s_, one), a_)), a_->diff(x)); +} + +RCP zeta(const RCP &s, const RCP &a) +{ + if (is_a_Number(*s)) { + if (rcp_static_cast(s)->is_zero()) { + if (is_a_Number(*a) && + rcp_static_cast(s)->is_negative()) { + return sub(div(minus_one, i2), a); + } else { + return sub(div(one, i2), a); + } + } else if (rcp_static_cast(s)->is_one()) { + throw std::runtime_error("Complex infinity is not yet implemented"); + } else if (is_a(*s) && is_a(*a)) { + // Implement Harmonic and simplify this + return rcp(new Zeta(s, a)); + } + } + return rcp(new Zeta(s, a)); +} + +RCP zeta(const RCP &s) +{ + return zeta(s, one); +} + } // CSymPy diff --git a/src/functions.h b/src/functions.h index 088e4ca8f8..750a5b451e 100644 --- a/src/functions.h +++ b/src/functions.h @@ -422,6 +422,52 @@ class LambertW : public Function { //! Create a new LambertW instance: RCP lambertw(const RCP &arg); + +class Zeta : public Function { +// Hurwitz zeta function (or Riemann zeta function). +// +// For `\operatorname{Re}(a) > 0` and `\operatorname{Re}(s) > 1`, this function is defined as +// +// .. math:: \zeta(s, a) = \sum_{n=0}^\infty \frac{1}{(n + a)^s}, +// +// where the standard choice of argument for :math:`n + a` is used. +// If no value is passed for :math:`a`, by this function assumes a default value +// of :math:`a = 1`, yielding the Riemann zeta function. + +private: + RCP s_; + RCP a_; + +public: + //! Zeta Constructor + Zeta(const RCP &s, const RCP &a); + //! Zeta Constructor + Zeta(const RCP &s); + //! \return Size of the hash + virtual std::size_t __hash__() const; + /*! Equality comparator + * \param o Object to be compared with + * \return whether the 2 objects are equal + * */ + virtual bool __eq__(const Basic &o) const; + virtual int compare(const Basic &o) const; + //! \return stringify version + virtual std::string __str__() const; + //! \return `s_` + inline RCP get_s() const { return s_; } + //! \return `a_` + inline RCP get_a() const { return a_; } + virtual vec_basic get_args() const { return {s_, a_}; } + //! \return `true` if canonical + bool is_canonical(const RCP &s, const RCP &a); + //! Differentiate w.r.t Symbol `x` + virtual RCP diff(const RCP &x) const; +}; + +//! Create a new Zeta instance: +RCP zeta(const RCP &s, const RCP &a); +RCP zeta(const RCP &s); + class FunctionSymbol : public Function { private: std::string name_; //! The `f` in `f(x+y)` From d7503cb56d93f6954319cd30fef9662efe556ba8 Mon Sep 17 00:00:00 2001 From: sushant Date: Sat, 2 Aug 2014 18:55:45 +0530 Subject: [PATCH 17/21] Added tests for zeta, updated test_travis.sh test_travis.sh now also searches for /usr/local/lib for libarb.so --- bin/test_travis.sh | 2 +- src/functions.cpp | 2 +- src/tests/basic/test_functions.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bin/test_travis.sh b/bin/test_travis.sh index d8466a596a..ecbf37d361 100755 --- a/bin/test_travis.sh +++ b/bin/test_travis.sh @@ -91,6 +91,6 @@ else if [[ "${WITH_ARB}" != "" ]]; then extra_libs="$extra_libs -larb -lflint" fi - g++ -std=c++0x -I$our_install_dir/include/ -L$our_install_dir/lib test_basic.cpp -lcsympy -lgmpxx -lgmp -lteuchos $extra_libs + g++ -std=c++0x -I$our_install_dir/include/ -L$our_install_dir/lib -L/usr/local/lib test_basic.cpp -lcsympy -lgmpxx -lgmp -lteuchos $extra_libs ./a.out fi diff --git a/src/functions.cpp b/src/functions.cpp index b38165bbe0..f770be9c21 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -2199,7 +2199,7 @@ RCP zeta(const RCP &s, const RCP &a) if (is_a_Number(*s)) { if (rcp_static_cast(s)->is_zero()) { if (is_a_Number(*a) && - rcp_static_cast(s)->is_negative()) { + rcp_static_cast(a)->is_negative()) { return sub(div(minus_one, i2), a); } else { return sub(div(one, i2), a); diff --git a/src/tests/basic/test_functions.cpp b/src/tests/basic/test_functions.cpp index 21341778fc..cfed8068c4 100644 --- a/src/tests/basic/test_functions.cpp +++ b/src/tests/basic/test_functions.cpp @@ -54,6 +54,7 @@ using CSymPy::asinh; using CSymPy::acosh; using CSymPy::atanh; using CSymPy::acoth; +using CSymPy::zeta; void test_sin() { @@ -1410,6 +1411,28 @@ void test_acoth() assert(eq(r1, r2)); } +void test_zeta() +{ + RCP x = symbol("x"); + RCP im1 = integer(-1); + RCP i2 = integer(2); + + RCP r1; + RCP r2; + + r1 = zeta(zero, x); + r2 = sub(div(one, i2), x); + assert(eq(r1, r2)); + + r1 = zeta(zero, im1); + r2 = div(one, i2); + assert(eq(r1, r2)); + + r1 = zeta(zero, i2); + r2 = div(integer(-3), i2); + assert(eq(r1, r2)); +} + int main(int argc, char* argv[]) { print_stack_on_segfault(); @@ -1440,5 +1463,6 @@ int main(int argc, char* argv[]) test_acosh(); test_atanh(); test_acoth(); + test_zeta(); return 0; } From 77a6e24202ae3b4883c9e530a5a3051005ea9b2d Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sat, 2 Aug 2014 21:09:19 +0530 Subject: [PATCH 18/21] include flint --- CMakeLists.txt | 12 +++++++++--- bin/test_travis.sh | 1 + cmake/FindFLINT.cmake | 9 +++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 cmake/FindFLINT.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9775479c61..8d86fe8456 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,14 +19,14 @@ endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb -I/usr/local/include/flint ") + "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb ") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-parameter") endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb -I/usr/local/include/flint") + "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-parameter") endif() @@ -63,9 +63,13 @@ set(WITH_ARB no CACHE BOOL "Build with Arb") if (WITH_ARB) + find_package(FLINT REQUIRED) + include_directories(${FLINT_INCLUDE_DIRS}) + set(LIBS ${LIBS} ${FLINT_LIBRARY}) + find_package(ARB REQUIRED) include_directories(${ARB_INCLUDE_DIRS}) - set(LIBS ${LIBS} ${ARB_LIBRARY} -lflint -larb) + set(LIBS ${LIBS} ${ARB_LIBRARY}) set(HAVE_CSYMPY_ARB yes) endif() @@ -186,6 +190,8 @@ message("WITH_ARB: ${WITH_ARB}") if (WITH_ARB) message("ARB_INCLUDE_DIRS: ${ARB_INCLUDE_DIRS}") message("ARB_LIBRARIES: ${ARB_LIBRARY}") + message("FLINT_INCLUDE_DIRS: ${FLINT_INCLUDE_DIRS}") + message("FLINT_LIBRARIES: ${FLINT_LIBRARY}") endif() message("Copying source of python wrappers into: ${CMAKE_CURRENT_BINARY_DIR}") diff --git a/bin/test_travis.sh b/bin/test_travis.sh index d8466a596a..92b43e2bfd 100755 --- a/bin/test_travis.sh +++ b/bin/test_travis.sh @@ -92,5 +92,6 @@ else extra_libs="$extra_libs -larb -lflint" fi g++ -std=c++0x -I$our_install_dir/include/ -L$our_install_dir/lib test_basic.cpp -lcsympy -lgmpxx -lgmp -lteuchos $extra_libs + export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./a.out fi diff --git a/cmake/FindFLINT.cmake b/cmake/FindFLINT.cmake new file mode 100644 index 0000000000..342956312d --- /dev/null +++ b/cmake/FindFLINT.cmake @@ -0,0 +1,9 @@ +find_path(FLINT_INCLUDE_DIR flint/flint.h $ENV{PYTHONHPC}/include) +find_library(FLINT flint $ENV{PYTHONHPC}/lib) +set(FLINT_LIBRARY ${FLINT}) +set(FLINT_INCLUDE_DIRS ${FLINT_INCLUDE_DIR}/flint) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FLINT DEFAULT_MSG FLINT_LIBRARY FLINT_INCLUDE_DIR) + +mark_as_advanced(FLINT_INCLUDE_DIR FLINT) From fdc11f2a6c298a9f9310cbbb484be40baf63caae Mon Sep 17 00:00:00 2001 From: sushant Date: Sun, 3 Aug 2014 12:10:20 +0530 Subject: [PATCH 19/21] Added API and function definition for Dirichlet_eta --- src/functions.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++ src/functions.h | 31 ++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/src/functions.cpp b/src/functions.cpp index f770be9c21..44a98b21e2 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -2219,4 +2219,65 @@ RCP zeta(const RCP &s) return zeta(s, one); } +Dirichlet_eta::Dirichlet_eta(const RCP &s) + : s_{s} +{ + CSYMPY_ASSERT(is_canonical(s_)) +} + +bool Dirichlet_eta::is_canonical(const RCP &s) +{ + if (eq(s, one)) return false; + if (!(is_a(*zeta(s)))) return false; + return true; +} + +std::size_t Dirichlet_eta::__hash__() const +{ + std::size_t seed = 0; + hash_combine(seed, *s_); + return seed; +} + +bool Dirichlet_eta::__eq__(const Basic &o) const +{ + if (is_a(o) && + eq(s_, static_cast(o).s_)) + return true; + return false; +} + +int Dirichlet_eta::compare(const Basic &o) const +{ + CSYMPY_ASSERT(is_a(o)) + return s_->__cmp__(*(static_cast(o).s_)); +} + + +std::string Dirichlet_eta::__str__() const +{ + std::ostringstream o; + o << "dirichlet_eta(" << *s_ << ")"; + return o.str(); +} + +RCP Dirichlet_eta::rewrite_as_zeta() const +{ + return mul(sub(one, pow(i2, sub(one, s_))), zeta(s_)); +} + +RCP dirichlet_eta(const RCP &s) +{ + if (is_a_Number(*s) && + rcp_static_cast(s)->is_one()) { + return log(i2); + } + RCP z = zeta(s); + if (is_a(*z)) { + return rcp(new Dirichlet_eta(s)); + } else { + return mul(sub(one, pow(i2, sub(one, s))), z); + } +} + } // CSymPy diff --git a/src/functions.h b/src/functions.h index 750a5b451e..76c16de20a 100644 --- a/src/functions.h +++ b/src/functions.h @@ -468,6 +468,37 @@ class Zeta : public Function { RCP zeta(const RCP &s, const RCP &a); RCP zeta(const RCP &s); +class Dirichlet_eta : public Function { +// See http://en.wikipedia.org/wiki/Dirichlet_eta_function + +private: + RCP s_; + +public: + //! Dirichlet_eta Constructor + Dirichlet_eta(const RCP &s); + //! \return Size of the hash + virtual std::size_t __hash__() const; + /*! Equality comparator + * \param o Object to be compared with + * \return whether the 2 objects are equal + * */ + virtual bool __eq__(const Basic &o) const; + virtual int compare(const Basic &o) const; + //! \return stringify version + virtual std::string __str__() const; + //! \return `s_` + inline RCP get_s() const { return s_; } + virtual vec_basic get_args() const { return {s_}; } + //! \return `true` if canonical + bool is_canonical(const RCP &s); + //! Rewrites in the form of zeta + RCP rewrite_as_zeta() const; +}; + +//! Create a new Dirichlet_eta instance: +RCP dirichlet_eta(const RCP &s); + class FunctionSymbol : public Function { private: std::string name_; //! The `f` in `f(x+y)` From 1d23c7657c6b26f52432bd8da6fc38991e04e013 Mon Sep 17 00:00:00 2001 From: sushant Date: Sun, 3 Aug 2014 14:08:00 +0530 Subject: [PATCH 20/21] Added tests for dirichlet_eta --- src/tests/basic/test_functions.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/tests/basic/test_functions.cpp b/src/tests/basic/test_functions.cpp index cfed8068c4..ceaff6ccfc 100644 --- a/src/tests/basic/test_functions.cpp +++ b/src/tests/basic/test_functions.cpp @@ -55,6 +55,7 @@ using CSymPy::acosh; using CSymPy::atanh; using CSymPy::acoth; using CSymPy::zeta; +using CSymPy::dirichlet_eta; void test_sin() { @@ -1433,6 +1434,24 @@ void test_zeta() assert(eq(r1, r2)); } +void test_dirichlet_eta() +{ + RCP x = symbol("x"); + RCP im1 = integer(-1); + RCP i2 = integer(2); + + RCP r1; + RCP r2; + + r1 = dirichlet_eta(one); + r2 = log(i2); + assert(eq(r1, r2)); + + r1 = dirichlet_eta(zero); + r2 = div(one, i2); + assert(eq(r1, r2)); +} + int main(int argc, char* argv[]) { print_stack_on_segfault(); @@ -1464,5 +1483,6 @@ int main(int argc, char* argv[]) test_atanh(); test_acoth(); test_zeta(); + test_dirichlet_eta(); return 0; } From 2eeaf524479216acf927fc432f244be5bc87a5d5 Mon Sep 17 00:00:00 2001 From: sushant Date: Tue, 5 Aug 2014 08:59:06 +0530 Subject: [PATCH 21/21] Remove WhiteSpace error from CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d86fe8456..8b9d9f7c93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb ") + "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -ggdb") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-parameter") endif()