Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cayley/extend complex #34

Closed
wants to merge 5 commits into from
Closed
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
54 changes: 24 additions & 30 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,40 @@ complex functions and rotation related quaternion usage.

* callables usable with all cayley_dickson types

Most **EVE** arithmetic and math functions are provided.
Most **EVE** arithmetic and math functions are provided. In particular, real analytic functions of one variable
can be quite naturally extended using the polar form described above from a mere complex implementation.

| | | | | |
|--------------|---------------|-----------------|------------|-----------------|
| [abs](@ref kyosu::abs ) | [acos](@ref kyosu::acos ) | [acosh](@ref kyosu::acosh ) | [acospi](@ref kyosu::acospi ) | [acot](@ref kyosu::acot ) |
| [acotpi](@ref kyosu::acotpi ) | [atanpi](@ref kyosu::atanpi ) | [acoth](@ref kyosu::acoth ) | [arg](@ref kyosu::arg ) | [acsc](@ref kyosu::acsc ) |
| [acscpi](@ref kyosu::acscpi ) | [acsch](@ref kyosu::acsch ) | [asec](@ref kyosu::asec ) | [asecpi](@ref kyosu::asecpi ) | [asech](@ref kyosu::asech ) |
| [asin](@ref kyosu::asin ) | [asinpi](@ref kyosu::asinpi ) | [asinh](@ref kyosu::asinh ) | [atan](@ref kyosu::atan ) | [atanh](@ref kyosu::atanh ) |
| [average](@ref kyosu::average ) | [ceil](@ref kyosu::ceil ) | [conj](@ref kyosu::conj ) | [cos](@ref kyosu::cos ) | [cosh](@ref kyosu::cosh ) |
| [cospi](@ref kyosu::cospi ) | [cot](@ref kyosu::cot ) | [cotpi](@ref kyosu::cotpi ) | [coth](@ref kyosu::coth ) | [convert](@ref kyosu::convert ) |
| [csc](@ref kyosu::csc ) | [cscpi](@ref kyosu::cscpi ) | [csch](@ref kyosu::csch ) | [dec](@ref kyosu::dec ) | [dist](@ref kyosu::dist ) |
| [dot](@ref kyosu::dot ) | [exp](@ref kyosu::exp ) | [exp10](@ref kyosu::exp10 ) | [exp2](@ref kyosu::exp2 ) | [exp_i](@ref kyosu::exp_i ) |
| [exp_ipi](@ref kyosu::exp_ipi ) | [expm1](@ref kyosu::expm1 ) | [expmx2](@ref kyosu::expmx2 ) | [expx2](@ref kyosu::expx2 ) | [fam](@ref kyosu::fam ) |
| [floor](@ref kyosu::floor ) | [fma](@ref kyosu::fma ) | [fms](@ref kyosu::fms ) | [fnma](@ref kyosu::fnma ) | [fnms](@ref kyosu::fnms ) |
| [frac](@ref kyosu::frac ) | [fsm](@ref kyosu::fsm ) | [from_polar](@ref kyosu::from_polar ) | [horner](@ref kyosu::horner ) | [hypot](@ref kyosu::hypot ) |
| [if_else](@ref kyosu::if_else ) | [inc](@ref kyosu::inc ) ||||
| [average](@ref kyosu::average ) | [beta](@ref kyosu::beta ) | [ceil](@ref kyosu::ceil ) | [conj](@ref kyosu::conj ) | [cos](@ref kyosu::cos ) |
| [cosh](@ref kyosu::cosh ) | [cospi](@ref kyosu::cospi ) | [cot](@ref kyosu::cot ) | [cotpi](@ref kyosu::cotpi ) | [coth](@ref kyosu::coth ) |
| [convert](@ref kyosu::convert ) | [csc](@ref kyosu::csc ) | [cscpi](@ref kyosu::cscpi ) | [csch](@ref kyosu::csch ) | [dec](@ref kyosu::dec ) |
| [deta](@ref kyosu::deta ) | [digamma](@ref kyosu::digamma ) | [dist](@ref kyosu::dist ) | [dot](@ref kyosu::dot ) | [erf](@ref kyosu::erf ) |
| [erfcx](@ref kyosu::erfcx ) | [erfi](@ref kyosu::erfi ) | [eta](@ref kyosu::eta ) | [exp](@ref kyosu::exp ) | [exp10](@ref kyosu::exp10 ) |
| [exp2](@ref kyosu::exp2 ) | [exp_i](@ref kyosu::exp_i ) | [exp_ipi](@ref kyosu::exp_ipi ) | [expm1](@ref kyosu::expm1 ) | [expmx2](@ref kyosu::expmx2 ) |
| [expx2](@ref kyosu::expx2 ) | [faddeeva](@ref kyosu::faddeeva ) | [fam](@ref kyosu::fam ) | [floor](@ref kyosu::floor ) | [fma](@ref kyosu::fma ) |
| [fms](@ref kyosu::fms ) | [fnma](@ref kyosu::fnma ) | [fnms](@ref kyosu::fnms ) | [frac](@ref kyosu::frac ) | [fsm](@ref kyosu::fsm ) |
| [from_polar](@ref kyosu::from_polar ) | [horner](@ref kyosu::horner ) | [hypot](@ref kyosu::hypot ) | [if_else](@ref kyosu::if_else )| [inc](@ref kyosu::inc ) |
| [ipart](@ref kyosu::ipart ) | [is_denormal](@ref kyosu::is_denormal ) | [is_equal](@ref kyosu::is_equal ) | [is_eqz](@ref kyosu::is_eqz ) | [is_finite](@ref kyosu::is_finite ) |
| [is_infinite](@ref kyosu::is_infinite ) | [is_imag](@ref kyosu::is_imag ) | [is_nan](@ref kyosu::is_nan ) | [is_nez](@ref kyosu::is_nez ) | [is_not_denormal](@ref kyosu::is_not_denormal ) |
| [is_not_equal](@ref kyosu::is_not_equal ) | [is_not_finite](@ref kyosu::is_not_finite ) | [is_not_infinite](@ref kyosu::is_not_finite ) | [is_not_nan](@ref kyosu::is_not_nan ) | [is_not_real](@ref kyosu::is_not_real ) |
| [is_not_equal](@ref kyosu::is_not_equal ) | [is_not_finite](@ref kyosu::is_not_finite ) | [is_not_infinite](@ref kyosu::is_not_finite ) | [is_not_nan](@ref kyosu::is_not_nan ) | [is_not_real](@ref kyosu::is_not_real ) |
| [is_pure](@ref kyosu::is_pure ) | [is_real](@ref kyosu::is_real ) | [is_unitary](@ref kyosu::is_unitary ) | [jpart](@ref kyosu::jpart ) | [kpart](@ref kyosu::kpart ) |
| [ldiv](@ref kyosu::ldiv ) | [lerp](@ref kyosu::lerp ) | [log](@ref kyosu::log ) | [log10](@ref kyosu::log10 ) | [log1p](@ref kyosu::log1p ) |
| [log_abs](@ref kyosu::log_abs ) | [log2](@ref kyosu::log2 ) | [lpnorm](@ref kyosu::lpnorm ) | [manhattan](@ref kyosu::manhattan ) | [minus](@ref kyosu::minus ) |
| [lpart](@ref kyosu::lpart ) | [lipart](@ref kyosu::lipart ) | [ljpart](@ref kyosu::ljpart ) | [lkpart](@ref kyosu::lkpart ) | |
| [nearest](@ref kyosu::nearest ) | [oneminus](@ref kyosu::oneminus ) | [pow](@ref kyosu::pow ) | [pow1p](@ref kyosu::pow1p ) | [pow_abs](@ref kyosu::pow_abs ) |
| [powm1](@ref kyosu::powm1 ) | [proj](@ref kyosu::proj ) | [pure](@ref kyosu::imag ) | [radinpi](@ref kyosu::radinpi )| [real](@ref kyosu::real ) |
| [rec](@ref kyosu::rec ) | [reldist](@ref kyosu::reldist ) | [reverse_horner](@ref kyosu::reverse_horner ) | [right_horner](@ref kyosu::right_horner ) | [right_reverse_horner](@ref kyosu::right_reverse_horner ) |
| [sec](@ref kyosu::sec ) | [secpi](@ref kyosu::secpi ) | [sech](@ref kyosu::sech ) | | |
| [sign](@ref kyosu::sign ) | [sin](@ref kyosu::sin ) | [sinc](@ref kyosu::sinc ) | [sincos](@ref kyosu::sincos ) | [sinpi](@ref kyosu::sinpi ) |
| [sinpicospi](@ref kyosu::sinpicospi ) | [sinh](@ref kyosu::sinh ) | [sinhcosh](@ref kyosu::sinhcosh ) | [slerp](@ref kyosu::slerp ) | [sqr](@ref kyosu::sqr ) |
| [sqr_abs](@ref kyosu::sqr_abs ) | [sqrt](@ref kyosu::sqrt ) | [tan](@ref kyosu::tan ) | [tanpi](@ref kyosu::tanpi ) | [tanh](@ref kyosu::tanh ) |
| [to_polar](@ref kyosu::to_polar ) | [trunc](@ref kyosu::trunc ) | | | |

* callables usable with complex or real only. These are mainly implementation of some classical meromorphic functions.

| | | | | |
|------------------|------------------|--------------------|------------------|---------------|
| [beta](@ref kyosu::beta ) | [deta](@ref kyosu::deta ) | [digamma](@ref kyosu::digamma ) | [erf](@ref kyosu::erf ) | [erfcx](@ref kyosu::erfcx ) |
| [erfi](@ref kyosu::erfi ) | [eta](@ref kyosu::eta ) | [faddeeva](@ref kyosu::faddeeva ) | [lambda](@ref kyosu::lambda ) | [lbeta](@ref kyosu::lbeta ) |
| [log_abs_gamma](@ref kyosu::log_abs_gamma ) | [log_gamma](@ref kyosu::log_gamma ) | [lrising_factorial](@ref kyosu::lrising_factorial ) | [rising_factorial](@ref kyosu::rising_factorial ) | [tgamma](@ref kyosu::tgamma ) |
| [zeta](@ref kyosu::zeta ) | | | | |
| [ldiv](@ref kyosu::ldiv ) | [lambda](@ref kyosu::lambda ) | [lbeta](@ref kyosu::lbeta ) | [lerp](@ref kyosu::lerp ) | [lipart](@ref kyosu::lipart ) |
| [ljpart](@ref kyosu::ljpart ) | [lkpart](@ref kyosu::lkpart ) | [log](@ref kyosu::log ) | [log2](@ref kyosu::log2 ) | [lpart](@ref kyosu::lpart ) |
| [lipart](@ref kyosu::lipart ) | [ljpart](@ref kyosu::ljpart ) | [lkpart](@ref kyosu::lkpart ) | [lpnorm](@ref kyosu::lpnorm ) | [lrising_factorial](@ref kyosu::lrising_factorial ) |
| [manhattan](@ref kyosu::manhattan ) | [minus](@ref kyosu::minus ) | [nearest](@ref kyosu::nearest ) | [oneminus](@ref kyosu::oneminus )| [pow](@ref kyosu::pow ) |
| [pow1p](@ref kyosu::pow1p ) | [pow_abs](@ref kyosu::pow_abs ) | [powm1](@ref kyosu::powm1 ) | [proj](@ref kyosu::proj ) | [pure](@ref kyosu::imag ) |
| [radinpi](@ref kyosu::radinpi ) | [real](@ref kyosu::real ) | [rec](@ref kyosu::rec ) | [reldist](@ref kyosu::reldist )| [reverse_horner](@ref kyosu::reverse_horner ) |
| [right_horner](@ref kyosu::right_horner ) | [right_reverse_horner](@ref kyosu::right_reverse_horner ) | [rising_factorial](@ref kyosu::rising_factorial ) | [sec](@ref kyosu::sec )| [secpi](@ref kyosu::secpi ) |
| [sech](@ref kyosu::sech ) | [sign](@ref kyosu::sign ) | [sin](@ref kyosu::sin ) | [sinc](@ref kyosu::sinc ) | [sincos](@ref kyosu::sincos ) |
| [sinpi](@ref kyosu::sinpi ) | [sinpicospi](@ref kyosu::sinpicospi ) | [sinh](@ref kyosu::sinh ) | [sinhcosh](@ref kyosu::sinhcosh ) | [slerp](@ref kyosu::slerp ) |
| [sqr](@ref kyosu::sqr ) | [sqr_abs](@ref kyosu::sqr_abs ) | [sqrt](@ref kyosu::sqrt ) | [tan](@ref kyosu::tan ) | [tanpi](@ref kyosu::tanpi ) |
| [tanh](@ref kyosu::tanh ) | [to_polar](@ref kyosu::to_polar ) | [tgamma](@ref kyosu::tgamma ) | [trunc](@ref kyosu::trunc ) | [zeta](@ref kyosu::zeta ) |


* callables usable with quaternion complex and real only

Expand Down
34 changes: 34 additions & 0 deletions include/kyosu/details/cayleyify.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//======================================================================================================================
/*
Kyosu - Complex Without Complexes
Copyright : KYOSU Contributors & Maintainers
SPDX-License-Identifier: BSL-1.0
*/
//======================================================================================================================
#pragma once

auto cayley_extend(auto f, auto z, auto... rs)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

care to explain what if of them do ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pb with sincos etc.-> cayley_extend2
pb with deta(k,z) etc. -> cayley_extend_rev
cayley_extend works for all other

{
auto p = kyosu::pure(z);
auto az = kyosu::abs(p);
auto c = f(kyosu::complex(kyosu::real(z), az), rs...);
return kyosu::real(c) + kyosu::ipart(c)*kyosu::sign(p);
}

auto cayley_extend_rev(auto f, auto z1, auto z2)
{
auto p = kyosu::pure(z2);
auto az2 = kyosu::abs(p);
auto c = f(z1, kyosu::complex(kyosu::real(z2), az2));
return kyosu::real(c) + kyosu::ipart(c)*kyosu::sign(p);
}

auto cayley_extend2(auto f, auto z, auto... rs)
{
auto p = kyosu::pure(z);
auto az = kyosu::abs(p);
auto [c1, c2] = f(kyosu::complex(kyosu::real(z), az), rs...);
auto s = kyosu::sign(p);
return kumi::tuple{ kyosu::real(c1) + kyosu::ipart(c1)*s
, kyosu::real(c2) + kyosu::ipart(c2)*s};
}
39 changes: 17 additions & 22 deletions include/kyosu/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <kyosu/functions/atan.hpp>
#include <kyosu/functions/atanh.hpp>
#include <kyosu/functions/average.hpp>
#include <kyosu/functions/beta.hpp>
#include <kyosu/functions/ceil.hpp>
#include <kyosu/functions/commutator.hpp>
#include <kyosu/functions/conj.hpp>
Expand All @@ -47,8 +48,14 @@
#include <kyosu/functions/cscpi.hpp>
#include <kyosu/functions/csch.hpp>
#include <kyosu/functions/dec.hpp>
#include <kyosu/functions/deta.hpp>
#include <kyosu/functions/digamma.hpp>
#include <kyosu/functions/dist.hpp>
#include <kyosu/functions/dot.hpp>
#include <kyosu/functions/erf.hpp>
#include <kyosu/functions/erfcx.hpp>
#include <kyosu/functions/erfi.hpp>
#include <kyosu/functions/eta.hpp>
#include <kyosu/functions/exp.hpp>
#include <kyosu/functions/exp10.hpp>
#include <kyosu/functions/exp2.hpp>
Expand All @@ -57,6 +64,8 @@
#include <kyosu/functions/expm1.hpp>
#include <kyosu/functions/expmx2.hpp>
#include <kyosu/functions/expx2.hpp>
#include <kyosu/functions/faddeeva.hpp>

#include <kyosu/functions/fam.hpp>
#include <kyosu/functions/floor.hpp>
#include <kyosu/functions/fma.hpp>
Expand Down Expand Up @@ -90,18 +99,24 @@
#include <kyosu/functions/is_unitary.hpp>
#include <kyosu/functions/jpart.hpp>
#include <kyosu/functions/kpart.hpp>
#include <kyosu/functions/lambda.hpp>
#include <kyosu/functions/lbeta.hpp>
#include <kyosu/functions/ldiv.hpp>
#include <kyosu/functions/lerp.hpp>
#include <kyosu/functions/log.hpp>
#include <kyosu/functions/log10.hpp>
#include <kyosu/functions/log1p.hpp>
#include <kyosu/functions/log_abs.hpp>
#include <kyosu/functions/log_abs_gamma.hpp>
#include <kyosu/functions/log_gamma.hpp>
#include <kyosu/functions/log2.hpp>
#include <kyosu/functions/lpart.hpp>
#include <kyosu/functions/lipart.hpp>
#include <kyosu/functions/ljpart.hpp>
#include <kyosu/functions/lkpart.hpp>
#include <kyosu/functions/lpnorm.hpp>
#include <kyosu/functions/lrising_factorial.hpp>
#include <kyosu/functions/rising_factorial.hpp>
#include <kyosu/functions/manhattan.hpp>
#include <kyosu/functions/maxabs.hpp>
#include <kyosu/functions/maxmag.hpp>
Expand Down Expand Up @@ -143,35 +158,15 @@
#include <kyosu/functions/tan.hpp>
#include <kyosu/functions/tanpi.hpp>
#include <kyosu/functions/tanh.hpp>
#include <kyosu/functions/tgamma.hpp>
#include <kyosu/functions/to_polar.hpp>
#include <kyosu/functions/trunc.hpp>

//======================================================================================================================
//! @brief Functions performing computations over complex or real elements only.
//======================================================================================================================

#include <kyosu/complex/beta.hpp>
#include <kyosu/complex/deta.hpp>
#include <kyosu/complex/digamma.hpp>
#include <kyosu/complex/erf.hpp>
#include <kyosu/complex/erfcx.hpp>
#include <kyosu/complex/erfi.hpp>
#include <kyosu/complex/eta.hpp>
#include <kyosu/complex/faddeeva.hpp>
#include <kyosu/complex/lambda.hpp>
#include <kyosu/complex/lbeta.hpp>
#include <kyosu/complex/log_abs_gamma.hpp>
#include <kyosu/complex/log_gamma.hpp>
#include <kyosu/complex/lrising_factorial.hpp>
#include <kyosu/complex/rising_factorial.hpp>
#include <kyosu/complex/tgamma.hpp>
#include <kyosu/complex/zeta.hpp>
#include <kyosu/functions/zeta.hpp>

//======================================================================================================================
//! @brief Functions performing computations over quaternion complex or real elements only.
//======================================================================================================================


#include <kyosu/functions/align.hpp>
#include <kyosu/functions/from_angle_axis.hpp>
#include <kyosu/functions/from_cylindrical.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ namespace kyosu
//!
//! **Parameters**
//!
//! * `x`,`y` : Values to process. Can be a mix of complex and real floating values and complex values.
//! * `x`,`y` : Values to process. Can be a mix of cayley_dickson and real floating values.
//!
//! **Return value**
//!
//! 1. If x and y are real typed values returns \f$\displaystyle \mathbf{B}(x,y) = \int_0^1 t^{x-1}(1-t)^{y-1}\mbox{d}t\f$
//! 2. if x or y is complex the value \f$\displaystyle \mathbf{B}(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}\f$ is returned.
//! 2. \f$\displaystyle \mathbf{B}(x,y) = \frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)}\f$ is returned.
//!
//! @groupheader{Example}
//!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ namespace kyosu
//! @code
//! namespace kyosu
//! {
//! template<unsigned_scalar_value K, eve::ordered_value T> constexpr auto deta(K k, T z) noexcept; //1
//! template<unsigned_scalar_value K, kyosu::concepts::complex T> constexpr auto deta(K k, T z) noexcept; //2
//! constexpr auto deta(unsigned_scalar_value auto k, auto z) noexcept;
//! }
//! @endcode
//!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ namespace kyosu
//! @code
//! namespace kyosu
//! {
//! template<kyosu::concepts::complex T> constexpr T digamma(T z) noexcept;
//! template<eve::floating_ordered_value T> constexpr T digamma(T z) noexcept;
//! constexpr auto digamma(auto z) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z` : real or complex value to process.
//! * `z` : value to process.
//!
//! **Return value**
//!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace kyosu
//! @var erf
//! @brief Computes the error function: \f$ \displaystyle
//! \mbox{erf}(x)=\frac{2}{\sqrt\pi}\int_0^{x} e^{-t^2}\mbox{d}t\f$ or
//! its analytic continuation in the complex plane
//! its extension to complex and general cayley-dickson values
//!
//! **Defined in Header**
//!
Expand All @@ -57,8 +57,8 @@ namespace kyosu
//! @code
//! namespace kyosu
//! {
//! template<eve::ordered_value T> constexpr auto erf(T z) noexcept; //1
//! template<kyosu::concepts::complex T> constexpr auto erf(T z) noexcept; //2
//! { template<eve::floating_ordered_value T> constexpr T erf(T z) noexcept;
//! template<kyosu::concepts::cayley_dickson T> constexpr T erf(T z) noexcept;
//! }
//! @endcode
//!
Expand All @@ -68,9 +68,7 @@ namespace kyosu
//!
//! **Return value**
//!
//! 1. a real input z returns eve::erf(z).
//!
//! 2. The value of the error function in the complex plane is returned
//! * The value of the error function is returned.
//!
//! @groupheader{Example}
//!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace kyosu
//! @code
//! namespace kyosu
//! {
//! template<eve::ordered_value T> constexpr auto erfcx(T z) noexcept; //1
//! template<kyosu::concepts::complex T> constexpr auto erfcx(T z) noexcept; //2
//! template<eve::ordered_value T> constexpr auto erfcx(T z) noexcept; //1
//! template<kyosu::concepts::cayley_dickson T> constexpr auto erfcx(T z) noexcept; //2
//! }
//! @endcode
//!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace kyosu::tags
{
auto over = eve::sqr(v) > 720;
auto r = eve::inf(eve::as(v))*eve::sign(v);
r = eve::if_else(over, r, -kyosu::imag(kyosu::erf(complex(eve::zero(eve::as(v)), -v))));
r = eve::if_else(over, r, -get<1>(kyosu::erf(complex(eve::zero(eve::as(v)), -v))));
return complex(r);
}

Expand Down Expand Up @@ -58,8 +58,8 @@ namespace kyosu
//! @code
//! namespace kyosu
//! {
//! template<eve::ordered_value T> constexpr auto erfi(T z) noexcept; //1
//! template<kyosu::concepts::complex T> constexpr auto erfi(T z) noexcept; //2
//! template<eve::ordered_value T> constexpr auto erfi(T z) noexcept; //1
//! template<kyosu::concepts::cayley_dickson T> constexpr auto erfi(T z) noexcept; //2
//! }
//! @endcode
//!
Expand Down
Loading