Skip to content

Commit

Permalink
Merge pull request #246 from bluescarni/pr/complex_specfun
Browse files Browse the repository at this point in the history
Initial support for Arb-based complex functions
  • Loading branch information
bluescarni committed Jun 5, 2020
2 parents 521fbd7 + 9547dc0 commit acfe1d9
Show file tree
Hide file tree
Showing 12 changed files with 1,173 additions and 393 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

project(mp++ VERSION 0.20 LANGUAGES CXX C)
project(mp++ VERSION 0.21 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

Expand Down Expand Up @@ -230,6 +230,12 @@ if(MPPP_WITH_MPFR)
"${MPPP_SRC_FILES}")
endif()

if(MPPP_WITH_ARB)
set(MPPP_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/arb.cpp"
"${MPPP_SRC_FILES}")
endif()

if(MPPP_WITH_MPC)
set(MPPP_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/complex.cpp"
Expand Down Expand Up @@ -275,8 +281,8 @@ if(MPPP_BUILD_STATIC_LIBRARY)
else()
# Setup of the mp++ shared library.
add_library(mp++ SHARED "${MPPP_SRC_FILES}")
set_property(TARGET mp++ PROPERTY VERSION "6.0")
set_property(TARGET mp++ PROPERTY SOVERSION 6)
set_property(TARGET mp++ PROPERTY VERSION "7.0")
set_property(TARGET mp++ PROPERTY SOVERSION 7)
set_property(TARGET mp++ PROPERTY DEFINE_SYMBOL "mppp_EXPORTS")
set_target_properties(mp++ PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(mp++ PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
Expand Down
22 changes: 22 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
Changelog
=========

0.21 (unreleased)
-----------------

New
~~~

- Additional special functions for :cpp:class:`~mppp::complex`
(inverse, reciprocal square root, n-th root)
(`#246 <https://github.com/bluescarni/mppp/pull/246>`__).
- Implement the detection of finite and infinite values
for :cpp:class:`~mppp::complex`
(`#246 <https://github.com/bluescarni/mppp/pull/246>`__).

Changes
~~~~~~~

- **BREAKING**: the :cpp:class:`~mppp::complex`
``cmp_abs()`` function has been renamed to
``cmpabs()`` for consistency with
:cpp:class:`~mppp::real`.


0.20 (2020-06-03)
-----------------

Expand Down
187 changes: 169 additions & 18 deletions doc/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,27 @@ The complex class
:return: a const or mutable pointer to the internal MPC structure.

.. cpp:function:: bool zero_p() const
.. cpp:function:: bool inf_p() const
.. cpp:function:: bool number_p() const
.. cpp:function:: bool is_one() const

Detect special values.

These member functions will return ``true`` if ``this`` is, respectively, zero or one,
These member functions will return ``true`` if ``this`` is, respectively:

* zero,
* a complex infinity (that is, at least one component of ``this``
is an infinity),
* a finite number (that is, both components of ``this`` are finite
numbers),
* one,

``false`` otherwise.

.. versionadded:: 0.21

The ``inf_p()`` and ``number_p()`` functions.

:return: the result of the detection.

.. cpp:function:: mpfr_prec_t get_prec() const
Expand Down Expand Up @@ -613,6 +627,12 @@ The complex class
.. cpp:function:: complex &arg()
.. cpp:function:: complex &sqr()
.. cpp:function:: complex &mul_i(int s = 0)
.. cpp:function:: complex &inv()

.. note::

The ``inv()`` function is available only if mp++ was
configured with the ``MPPP_WITH_ARB`` option enabled.

In-place basic aritmetic functions.

Expand All @@ -626,19 +646,51 @@ The complex class
* :math:`\arg z`,
* :math:`z^2`,
* :math:`\imath z` (if :math:`s\geq 0`) or :math:`-\imath z` (if :math:`s < 0`),
* :math:`1/z`,

where :math:`z` is the current value of ``this``.

The ``inv()`` function follows the conventions laid out in Annex G
of the C99 standard when ``this`` is zero or an infinity.

.. versionadded:: 0.21

The ``inv()`` function.

:return: a reference to ``this``.

:exception std\:\:invalid_argument: if the conversion between Arb and MPC types
fails because of (unlikely) overflow conditions.

.. cpp:function:: complex &sqrt()
.. cpp:function:: complex &rec_sqrt()

.. note::

The ``rec_sqrt()`` function is available only if mp++ was
configured with the ``MPPP_WITH_ARB`` option enabled.

In-place square root.
In-place roots.

This member function will set ``this`` to :math:`\sqrt{z}`, where :math:`z` is the current value of ``this``.
These member functions will set ``this`` to, respectively:

* :math:`\sqrt{z}`,
* :math:`1 / \sqrt{z}`,

where :math:`z` is the current value of ``this``.

The ``rec_sqrt()`` function follows the conventions laid out in Annex G
of the C99 standard when ``this`` is zero or an infinity.

.. versionadded:: 0.21

The ``rec_sqrt()`` function.

:return: a reference to ``this``.

:exception std\:\:invalid_argument: if the conversion between Arb and MPC types
fails because of (unlikely) overflow conditions.

.. cpp:function:: complex &exp()
.. cpp:function:: complex &log()
.. cpp:function:: complex &log10()
Expand Down Expand Up @@ -1200,11 +1252,17 @@ Arithmetic
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::proj(mppp::complex &rop, T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::sqr(mppp::complex &rop, T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::mul_i(mppp::complex &rop, T &&z, int s = 0)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::inv(mppp::complex &rop, T &&z)
.. cpp:function:: mppp::real &mppp::abs(mppp::real &rop, const mppp::complex &z)
.. cpp:function:: mppp::real &mppp::norm(mppp::real &rop, const mppp::complex &z)
.. cpp:function:: mppp::real &mppp::arg(mppp::real &rop, const mppp::complex &z)

Basic unary arithmetic functions.
.. note::

The ``inv()`` function is available only if mp++ was
configured with the ``MPPP_WITH_ARB`` option enabled.

Basic binary arithmetic functions.

These functions will set *rop* to, respectively:

Expand All @@ -1213,26 +1271,43 @@ Arithmetic
* the projection of :math:`z` into Riemann sphere,
* :math:`z^2`,
* :math:`\imath z` (if :math:`s\geq 0`) or :math:`-\imath z` (if :math:`s < 0`),
* :math:`1/z`,
* :math:`\left| z \right|`,
* :math:`\left| z \right|^2`,
* :math:`\arg z`.

The precision of the result will be equal to the precision of *z*.

The ``inv()`` function follows the conventions laid out in Annex G
of the C99 standard when *z* is zero or an infinity.

.. versionadded:: 0.21

The ``inv()`` function.

:param rop: the return value.
:param z: the argument.

:return: a reference to *rop*.

:exception std\:\:invalid_argument: if the conversion between Arb and MPC types
fails because of (unlikely) overflow conditions.

.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::neg(T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::conj(T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::proj(T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::sqr(T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::mul_i(T &&z, int s = 0)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::inv(T &&z)
.. cpp:function:: mppp::real mppp::abs(const mppp::complex &z)
.. cpp:function:: mppp::real mppp::norm(const mppp::complex &z)
.. cpp:function:: mppp::real mppp::arg(const mppp::complex &z)

.. note::

The ``inv()`` function is available only if mp++ was
configured with the ``MPPP_WITH_ARB`` option enabled.

Basic unary arithmetic functions.

These functions will return, respectively:
Expand All @@ -1242,16 +1317,27 @@ Arithmetic
* the projection of :math:`z` into Riemann sphere,
* :math:`z^2`,
* :math:`\imath z` (if :math:`s\geq 0`) or :math:`-\imath z` (if :math:`s < 0`),
* :math:`1/z`,
* :math:`\left| z \right|`,
* :math:`\left| z \right|^2`,
* :math:`\arg z`.

The precision of the result will be equal to the precision of *z*.

The ``inv()`` function follows the conventions laid out in Annex G
of the C99 standard when *z* is zero or an infinity.

.. versionadded:: 0.21

The ``inv()`` function.

:param z: the argument.

:return: the result of the operation.

:exception std\:\:invalid_argument: if the conversion between Arb and MPC types
fails because of (unlikely) overflow conditions.

.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::mul_2ui(mppp::complex &rop, T &&c, unsigned long n)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::mul_2si(mppp::complex &rop, T &&c, long n)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::div_2ui(mppp::complex &rop, T &&c, unsigned long n)
Expand Down Expand Up @@ -1296,7 +1382,7 @@ Arithmetic
Comparison
~~~~~~~~~~

.. cpp:function:: int mppp::cmp_abs(const mppp::complex &a, const mppp::complex &b)
.. cpp:function:: int mppp::cmpabs(const mppp::complex &a, const mppp::complex &b)

Three-way comparison of absolute values.

Expand All @@ -1316,43 +1402,108 @@ Comparison
:exception std\:\:domain_error: if at least one of the components of *a* and *b* is NaN.

.. cpp:function:: bool mppp::zero_p(const mppp::complex &c)
.. cpp:function:: bool mppp::inf_p(const mppp::complex &c)
.. cpp:function:: bool mppp::number_p(const mppp::complex &c)
.. cpp:function:: bool mppp::is_one(const mppp::complex &c)

Detect special values.

These functions will return ``true`` if *c* is, respectively, zero or one,
These functions will return ``true`` if *c* is, respectively:

* zero,
* a complex infinity (that is, at least one component of *c*
is an infinity),
* a finite number (that is, both components of *c* are finite
numbers),
* one,

``false`` otherwise.

.. versionadded:: 0.21

The ``inf_p()`` and ``number_p()`` functions.

:param c: the input argument.

:return: the result of the detection.

Roots
~~~~~

.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::sqrt(mppp::complex &rop, T &&op)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::sqrt(mppp::complex &rop, T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::rec_sqrt(mppp::complex &rop, T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex &mppp::rootn_ui(mppp::complex &rop, T &&z, unsigned long k)

.. note::

The ``rec_sqrt()`` and ``rootn_ui()`` functions are available only if mp++ was
configured with the ``MPPP_WITH_ARB`` option enabled.

Binary :cpp:class:`~mppp::complex` roots.

These functions will set *rop* to, respectively:

* :math:`\sqrt{z}`,
* :math:`1 / \sqrt{z}`,
* :math:`\sqrt[k]{z}`.

The precision of the result will be equal to the precision of *z*.

The ``rec_sqrt()`` function follows the conventions laid out in Annex G
of the C99 standard when *z* is zero or an infinity.

The ``rootn_ui()`` function computes the principal *k*-th root of *z*. If
*k* is zero, *rop* will be set to NaN.

Binary :cpp:class:`~mppp::complex` square root.
.. versionadded:: 0.21

This function will compute the square root of *op* and store it
into *rop*. The precision of the result will be equal to the precision
of *op*.
The ``rec_sqrt()`` and ``rootn_ui()`` functions.

:param rop: the return value.
:param op: the operand.
:param z: the operand.
:param k: the degree of the root.

:return: a reference to *rop*.

.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::sqrt(T &&r)
:exception std\:\:invalid_argument: if the conversion between Arb and MPC types
fails because of (unlikely) overflow conditions.

.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::sqrt(T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::rec_sqrt(T &&z)
.. cpp:function:: template <mppp::cvr_complex T> mppp::complex mppp::rootn_ui(T &&z, unsigned long k)

.. note::

Unary :cpp:class:`~mppp::complex` square root.
The ``rec_sqrt()`` and ``rootn_ui()`` functions are available only if mp++ was
configured with the ``MPPP_WITH_ARB`` option enabled.

This function will compute and return the square root of *r*.
The precision of the result will be equal to the precision of *r*.
Unary :cpp:class:`~mppp::complex` roots.

:param r: the operand.
These functions will return, respectively:

* :math:`\sqrt{z}`,
* :math:`1 / \sqrt{z}`,
* :math:`\sqrt[k]{z}`.

The precision of the result will be equal to the precision of *z*.

The ``rec_sqrt()`` function follows the conventions laid out in Annex G
of the C99 standard when *z* is zero or an infinity.

The ``rootn_ui()`` function computes the principal *k*-th root of *z*. If
*k* is zero, *rop* will be set to NaN.

.. versionadded:: 0.21

The ``rec_sqrt()`` and ``rootn_ui()`` functions.

:param z: the operand.
:param k: the degree of the root.

:return: the result of the operation.

:return: the square root of *r*.
:exception std\:\:invalid_argument: if the conversion between Arb and MPC types
fails because of (unlikely) overflow conditions.

Exponentiation
~~~~~~~~~~~~~~
Expand Down

0 comments on commit acfe1d9

Please sign in to comment.